2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebKitDLL.h"
29 #include "WebScrollBar.h"
31 #pragma warning(push, 0)
32 #include <WebCore/GraphicsContext.h>
33 #include <WebCore/PlatformMouseEvent.h>
34 #include <WebCore/Scrollbar.h>
35 #include <WebCore/ScrollbarTheme.h>
38 using namespace WebCore;
40 // WebScrollBar ---------------------------------------------------------------------
42 WebScrollBar::WebScrollBar()
44 , m_containingWindow(0)
45 , m_currentPosition(0)
48 gClassNameCount.add("WebScrollBar");
51 WebScrollBar::~WebScrollBar()
54 gClassNameCount.remove("WebScrollBar");
57 WebScrollBar* WebScrollBar::createInstance()
59 WebScrollBar* instance = new WebScrollBar();
64 // IUnknown -------------------------------------------------------------------
66 HRESULT STDMETHODCALLTYPE WebScrollBar::QueryInterface(REFIID riid, void** ppvObject)
69 if (IsEqualGUID(riid, IID_IUnknown))
70 *ppvObject = static_cast<IUnknown*>(this);
71 else if (IsEqualGUID(riid, IID_IWebScrollBarPrivate))
72 *ppvObject = static_cast<IWebScrollBarPrivate*>(this);
80 ULONG STDMETHODCALLTYPE WebScrollBar::AddRef(void)
85 ULONG STDMETHODCALLTYPE WebScrollBar::Release(void)
87 ULONG newRef = --m_refCount;
94 // IWebScrollBarPrivate ------------------------------------------------------------------
95 HRESULT STDMETHODCALLTYPE WebScrollBar::init(
96 /* [in] */ IWebScrollBarDelegatePrivate* delegate,
97 /* [in] */ OLE_HANDLE containingWindow,
98 /* [in] */ WebScrollBarOrientation orientation,
99 /* [in] */ WebScrollBarControlSize controlSize)
101 if (!delegate || !containingWindow)
103 ScrollbarOrientation webCoreOrientation = (ScrollbarOrientation) orientation;
104 ScrollbarControlSize webCoreControlSize = (ScrollbarControlSize) controlSize;
105 m_delegate = delegate;
106 m_scrollBar = Scrollbar::createNativeScrollbar(this, webCoreOrientation, webCoreControlSize);
109 m_containingWindow = (HWND)(ULONG64)containingWindow;
113 HRESULT STDMETHODCALLTYPE WebScrollBar::setEnabled(
114 /* [in] */ BOOL enabled)
116 m_scrollBar->setEnabled(!!enabled);
120 HRESULT STDMETHODCALLTYPE WebScrollBar::setSteps(
121 /* [in] */ int lineStep,
122 /* [in] */ int pageStep)
124 m_scrollBar->setSteps(lineStep, pageStep);
128 HRESULT STDMETHODCALLTYPE WebScrollBar::setProportion(
129 /* [in] */ int visibleSize,
130 /* [in] */ int totalSize)
132 m_scrollBar->setProportion(visibleSize, totalSize);
136 HRESULT STDMETHODCALLTYPE WebScrollBar::setRect(
137 /* [in] */ RECT bounds)
139 IntRect rect(bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
140 m_scrollBar->setFrameRect(rect);
144 HRESULT STDMETHODCALLTYPE WebScrollBar::setValue(
145 /* [in] */ int value)
147 m_currentPosition = value;
151 HRESULT STDMETHODCALLTYPE WebScrollBar::value(
152 /* [retval][out] */ int* value)
156 *value = m_currentPosition;
160 HRESULT STDMETHODCALLTYPE WebScrollBar::paint(
162 /* [in] */ RECT damageRect)
164 GraphicsContext context(dc);
165 IntRect rect(damageRect.left, damageRect.top, damageRect.right-damageRect.left, damageRect.bottom-damageRect.top);
166 m_scrollBar->paint(&context, rect);
170 HRESULT STDMETHODCALLTYPE WebScrollBar::frameRect(
171 /* [retval][out] */ RECT* bounds)
175 IntRect rect = m_scrollBar->frameRect();
176 bounds->left = rect.x();
177 bounds->right = rect.maxX();
178 bounds->top = rect.y();
179 bounds->bottom = rect.maxY();
183 HRESULT STDMETHODCALLTYPE WebScrollBar::width(
184 /* [retval][out] */ int* w)
188 *w = m_scrollBar->width();
192 HRESULT STDMETHODCALLTYPE WebScrollBar::height(
193 /* [retval][out] */ int* h)
197 *h = m_scrollBar->height();
201 HRESULT STDMETHODCALLTYPE WebScrollBar::requestedWidth(
202 /* [retval][out] */ int* w)
207 *w = m_scrollBar->orientation() == VerticalScrollbar ? ScrollbarTheme::nativeTheme()->scrollbarThickness(m_scrollBar->controlSize()) : -1;
211 HRESULT STDMETHODCALLTYPE WebScrollBar::requestedHeight(
212 /* [retval][out] */ int* h)
217 *h = m_scrollBar->orientation() == HorizontalScrollbar ? ScrollbarTheme::nativeTheme()->scrollbarThickness(m_scrollBar->controlSize()) : -1;
222 HRESULT STDMETHODCALLTYPE WebScrollBar::handleMouseEvent(
228 PlatformMouseEvent mouseEvent((HWND)(ULONG64)window, msg, wParam, lParam);
231 m_scrollBar->mouseDown(mouseEvent);
234 m_scrollBar->mouseUp();
237 m_scrollBar->mouseMoved(mouseEvent);
244 HRESULT STDMETHODCALLTYPE WebScrollBar::scroll(
245 WebScrollDirection direction,
246 WebScrollGranularity granularity,
249 ScrollDirection webCoreScrollDirection = (ScrollDirection) direction;
250 ScrollGranularity webCoreGranularity = (ScrollGranularity) granularity;
251 ScrollableArea::scroll(webCoreScrollDirection, webCoreGranularity, multiplier);
255 // ScrollableArea -------------------------------------------------------
257 int WebScrollBar::scrollSize(ScrollbarOrientation orientation) const
259 return (orientation == m_scrollBar->orientation()) ? (m_scrollBar->totalSize() - m_scrollBar->visibleSize()) : 0;
262 int WebScrollBar::scrollPosition(Scrollbar*) const
264 return m_currentPosition;
267 void WebScrollBar::setScrollOffset(const IntPoint& offset)
269 m_currentPosition = (m_scrollBar->orientation() == HorizontalScrollbar) ? offset.x() : offset.y();
270 m_delegate->valueChanged(this);
273 void WebScrollBar::invalidateScrollbarRect(Scrollbar*, const IntRect& rect)
276 ::InvalidateRect(m_containingWindow, &r, false);
279 Scrollbar* WebScrollBar::horizontalScrollbar() const
281 return m_scrollBar->orientation() == HorizontalScrollbar ? m_scrollBar.get() : 0;
284 Scrollbar* WebScrollBar::verticalScrollbar() const
286 return m_scrollBar->orientation() == VerticalScrollbar ? m_scrollBar.get() : 0;