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 #include <WebCore/GraphicsContext.h>
32 #include <WebCore/PlatformMouseEvent.h>
33 #include <WebCore/Scrollbar.h>
34 #include <WebCore/ScrollbarTheme.h>
36 using namespace WebCore;
38 // WebScrollBar ---------------------------------------------------------------------
40 WebScrollBar::WebScrollBar()
42 , m_containingWindow(0)
43 , m_currentPosition(0)
46 gClassNameCount.add("WebScrollBar");
49 WebScrollBar::~WebScrollBar()
52 gClassNameCount.remove("WebScrollBar");
55 WebScrollBar* WebScrollBar::createInstance()
57 WebScrollBar* instance = new WebScrollBar();
62 // IUnknown -------------------------------------------------------------------
64 HRESULT STDMETHODCALLTYPE WebScrollBar::QueryInterface(REFIID riid, void** ppvObject)
67 if (IsEqualGUID(riid, IID_IUnknown))
68 *ppvObject = static_cast<IUnknown*>(this);
69 else if (IsEqualGUID(riid, IID_IWebScrollBarPrivate))
70 *ppvObject = static_cast<IWebScrollBarPrivate*>(this);
78 ULONG STDMETHODCALLTYPE WebScrollBar::AddRef(void)
83 ULONG STDMETHODCALLTYPE WebScrollBar::Release(void)
85 ULONG newRef = --m_refCount;
92 // IWebScrollBarPrivate ------------------------------------------------------------------
93 HRESULT STDMETHODCALLTYPE WebScrollBar::init(
94 /* [in] */ IWebScrollBarDelegatePrivate* delegate,
95 /* [in] */ OLE_HANDLE containingWindow,
96 /* [in] */ WebScrollBarOrientation orientation,
97 /* [in] */ WebScrollBarControlSize controlSize)
99 if (!delegate || !containingWindow)
101 ScrollbarOrientation webCoreOrientation = (ScrollbarOrientation) orientation;
102 ScrollbarControlSize webCoreControlSize = (ScrollbarControlSize) controlSize;
103 m_delegate = delegate;
104 m_scrollBar = Scrollbar::createNativeScrollbar(this, webCoreOrientation, webCoreControlSize);
107 m_containingWindow = (HWND)(ULONG64)containingWindow;
111 HRESULT STDMETHODCALLTYPE WebScrollBar::setEnabled(
112 /* [in] */ BOOL enabled)
114 m_scrollBar->setEnabled(!!enabled);
118 HRESULT STDMETHODCALLTYPE WebScrollBar::setSteps(
119 /* [in] */ int lineStep,
120 /* [in] */ int pageStep)
122 m_scrollBar->setSteps(lineStep, pageStep);
126 HRESULT STDMETHODCALLTYPE WebScrollBar::setProportion(
127 /* [in] */ int visibleSize,
128 /* [in] */ int totalSize)
130 m_scrollBar->setProportion(visibleSize, totalSize);
134 HRESULT STDMETHODCALLTYPE WebScrollBar::setRect(
135 /* [in] */ RECT bounds)
137 IntRect rect(bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
138 m_scrollBar->setFrameRect(rect);
142 HRESULT STDMETHODCALLTYPE WebScrollBar::setValue(
143 /* [in] */ int value)
145 m_currentPosition = value;
146 ScrollableArea::scrollToOffsetWithoutAnimation(m_scrollBar->orientation(), m_currentPosition);
150 HRESULT STDMETHODCALLTYPE WebScrollBar::value(
151 /* [retval][out] */ int* value)
155 *value = m_currentPosition;
159 HRESULT STDMETHODCALLTYPE WebScrollBar::paint(
161 /* [in] */ RECT damageRect)
163 GraphicsContext context(dc);
164 IntRect rect(damageRect.left, damageRect.top, damageRect.right-damageRect.left, damageRect.bottom-damageRect.top);
165 m_scrollBar->paint(&context, rect);
169 HRESULT STDMETHODCALLTYPE WebScrollBar::frameRect(
170 /* [retval][out] */ RECT* bounds)
174 IntRect rect = m_scrollBar->frameRect();
175 bounds->left = rect.x();
176 bounds->right = rect.maxX();
177 bounds->top = rect.y();
178 bounds->bottom = rect.maxY();
182 HRESULT STDMETHODCALLTYPE WebScrollBar::width(
183 /* [retval][out] */ int* w)
187 *w = m_scrollBar->width();
191 HRESULT STDMETHODCALLTYPE WebScrollBar::height(
192 /* [retval][out] */ int* h)
196 *h = m_scrollBar->height();
200 HRESULT STDMETHODCALLTYPE WebScrollBar::requestedWidth(
201 /* [retval][out] */ int* w)
206 *w = m_scrollBar->orientation() == VerticalScrollbar ? ScrollbarTheme::nativeTheme()->scrollbarThickness(m_scrollBar->controlSize()) : -1;
210 HRESULT STDMETHODCALLTYPE WebScrollBar::requestedHeight(
211 /* [retval][out] */ int* h)
216 *h = m_scrollBar->orientation() == HorizontalScrollbar ? ScrollbarTheme::nativeTheme()->scrollbarThickness(m_scrollBar->controlSize()) : -1;
221 HRESULT STDMETHODCALLTYPE WebScrollBar::handleMouseEvent(
227 PlatformMouseEvent mouseEvent((HWND)(ULONG64)window, msg, wParam, lParam);
230 m_scrollBar->mouseDown(mouseEvent);
233 m_scrollBar->mouseUp();
236 m_scrollBar->mouseMoved(mouseEvent);
243 HRESULT STDMETHODCALLTYPE WebScrollBar::scroll(
244 WebScrollDirection direction,
245 WebScrollGranularity granularity,
248 ScrollDirection webCoreScrollDirection = (ScrollDirection) direction;
249 ScrollGranularity webCoreGranularity = (ScrollGranularity) granularity;
250 ScrollableArea::scroll(webCoreScrollDirection, webCoreGranularity, multiplier);
254 // ScrollableArea -------------------------------------------------------
256 int WebScrollBar::scrollSize(ScrollbarOrientation orientation) const
258 return (orientation == m_scrollBar->orientation()) ? (m_scrollBar->totalSize() - m_scrollBar->visibleSize()) : 0;
261 int WebScrollBar::scrollPosition(Scrollbar*) const
263 return m_currentPosition;
266 void WebScrollBar::setScrollOffset(const IntPoint& offset)
268 m_currentPosition = (m_scrollBar->orientation() == HorizontalScrollbar) ? offset.x() : offset.y();
269 m_delegate->valueChanged(this);
272 void WebScrollBar::invalidateScrollbarRect(Scrollbar*, const IntRect& rect)
275 ::InvalidateRect(m_containingWindow, &r, false);
278 Scrollbar* WebScrollBar::horizontalScrollbar() const
280 return m_scrollBar->orientation() == HorizontalScrollbar ? m_scrollBar.get() : 0;
283 Scrollbar* WebScrollBar::verticalScrollbar() const
285 return m_scrollBar->orientation() == VerticalScrollbar ? m_scrollBar.get() : 0;