|
1 /* |
|
2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
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. |
|
12 * |
|
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. |
|
24 */ |
|
25 |
|
26 #include "config.h" |
|
27 #include "WebKitDLL.h" |
|
28 #include "WebKit.h" |
|
29 #include "WebScrollBar.h" |
|
30 |
|
31 #pragma warning(push, 0) |
|
32 #include <WebCore/GraphicsContext.h> |
|
33 #include <WebCore/PlatformMouseEvent.h> |
|
34 #include <WebCore/PlatformScrollBar.h> |
|
35 #pragma warning(pop) |
|
36 |
|
37 using namespace WebCore; |
|
38 |
|
39 // WebScrollBar --------------------------------------------------------------------- |
|
40 |
|
41 WebScrollBar::WebScrollBar() |
|
42 : m_refCount(0) |
|
43 { |
|
44 gClassCount++; |
|
45 } |
|
46 |
|
47 WebScrollBar::~WebScrollBar() |
|
48 { |
|
49 gClassCount--; |
|
50 } |
|
51 |
|
52 WebScrollBar* WebScrollBar::createInstance() |
|
53 { |
|
54 WebScrollBar* instance = new WebScrollBar(); |
|
55 instance->AddRef(); |
|
56 return instance; |
|
57 } |
|
58 |
|
59 // IUnknown ------------------------------------------------------------------- |
|
60 |
|
61 HRESULT STDMETHODCALLTYPE WebScrollBar::QueryInterface(REFIID riid, void** ppvObject) |
|
62 { |
|
63 *ppvObject = 0; |
|
64 if (IsEqualGUID(riid, IID_IUnknown)) |
|
65 *ppvObject = static_cast<IUnknown*>(this); |
|
66 else if (IsEqualGUID(riid, IID_IWebScrollBarPrivate)) |
|
67 *ppvObject = static_cast<IWebScrollBarPrivate*>(this); |
|
68 else |
|
69 return E_NOINTERFACE; |
|
70 |
|
71 AddRef(); |
|
72 return S_OK; |
|
73 } |
|
74 |
|
75 ULONG STDMETHODCALLTYPE WebScrollBar::AddRef(void) |
|
76 { |
|
77 return ++m_refCount; |
|
78 } |
|
79 |
|
80 ULONG STDMETHODCALLTYPE WebScrollBar::Release(void) |
|
81 { |
|
82 ULONG newRef = --m_refCount; |
|
83 if (!newRef) |
|
84 delete(this); |
|
85 |
|
86 return newRef; |
|
87 } |
|
88 |
|
89 // IWebScrollBarPrivate ------------------------------------------------------------------ |
|
90 HRESULT STDMETHODCALLTYPE WebScrollBar::init( |
|
91 /* [in] */ IWebScrollBarDelegatePrivate* delegate, |
|
92 /* [in] */ OLE_HANDLE containingWindow, |
|
93 /* [in] */ WebScrollBarOrientation orientation, |
|
94 /* [in] */ WebScrollBarControlSize controlSize) |
|
95 { |
|
96 if (!delegate || !containingWindow) |
|
97 return E_FAIL; |
|
98 ScrollbarOrientation webCoreOrientation = (ScrollbarOrientation) orientation; |
|
99 ScrollbarControlSize webCoreControlSize = (ScrollbarControlSize) controlSize; |
|
100 m_delegate = delegate; |
|
101 m_scrollBar = new PlatformScrollbar(this, webCoreOrientation, webCoreControlSize); |
|
102 if (!m_scrollBar) |
|
103 return E_FAIL; |
|
104 m_scrollBar->setContainingWindow((HWND)(ULONG64)containingWindow); |
|
105 return S_OK; |
|
106 } |
|
107 |
|
108 HRESULT STDMETHODCALLTYPE WebScrollBar::setEnabled( |
|
109 /* [in] */ BOOL enabled) |
|
110 { |
|
111 m_scrollBar->setEnabled(!!enabled); |
|
112 return S_OK; |
|
113 } |
|
114 |
|
115 HRESULT STDMETHODCALLTYPE WebScrollBar::setSteps( |
|
116 /* [in] */ int lineStep, |
|
117 /* [in] */ int pageStep) |
|
118 { |
|
119 m_scrollBar->setSteps(lineStep, pageStep); |
|
120 return S_OK; |
|
121 } |
|
122 |
|
123 HRESULT STDMETHODCALLTYPE WebScrollBar::setProportion( |
|
124 /* [in] */ int visibleSize, |
|
125 /* [in] */ int totalSize) |
|
126 { |
|
127 m_scrollBar->setProportion(visibleSize, totalSize); |
|
128 return S_OK; |
|
129 } |
|
130 |
|
131 HRESULT STDMETHODCALLTYPE WebScrollBar::setRect( |
|
132 /* [in] */ RECT bounds) |
|
133 { |
|
134 IntRect rect(bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top); |
|
135 m_scrollBar->setRect(rect); |
|
136 return S_OK; |
|
137 } |
|
138 |
|
139 HRESULT STDMETHODCALLTYPE WebScrollBar::setValue( |
|
140 /* [in] */ int value) |
|
141 { |
|
142 m_scrollBar->setValue(value); |
|
143 return S_OK; |
|
144 } |
|
145 |
|
146 HRESULT STDMETHODCALLTYPE WebScrollBar::value( |
|
147 /* [retval][out] */ int* value) |
|
148 { |
|
149 if (!value) |
|
150 return E_POINTER; |
|
151 *value = m_scrollBar->value(); |
|
152 return S_OK; |
|
153 } |
|
154 |
|
155 HRESULT STDMETHODCALLTYPE WebScrollBar::paint( |
|
156 /* [in] */ HDC dc, |
|
157 /* [in] */ RECT damageRect) |
|
158 { |
|
159 GraphicsContext context(dc); |
|
160 IntRect rect(damageRect.left, damageRect.top, damageRect.right-damageRect.left, damageRect.bottom-damageRect.top); |
|
161 m_scrollBar->paint(&context, rect); |
|
162 return S_OK; |
|
163 } |
|
164 |
|
165 HRESULT STDMETHODCALLTYPE WebScrollBar::frameGeometry( |
|
166 /* [retval][out] */ RECT* bounds) |
|
167 { |
|
168 if (!bounds) |
|
169 return E_POINTER; |
|
170 IntRect rect = m_scrollBar->frameGeometry(); |
|
171 bounds->left = rect.x(); |
|
172 bounds->right = rect.right(); |
|
173 bounds->top = rect.y(); |
|
174 bounds->bottom = rect.bottom(); |
|
175 return S_OK; |
|
176 } |
|
177 |
|
178 HRESULT STDMETHODCALLTYPE WebScrollBar::width( |
|
179 /* [retval][out] */ int* w) |
|
180 { |
|
181 if (!w) |
|
182 return E_POINTER; |
|
183 *w = m_scrollBar->width(); |
|
184 return S_OK; |
|
185 } |
|
186 |
|
187 HRESULT STDMETHODCALLTYPE WebScrollBar::height( |
|
188 /* [retval][out] */ int* h) |
|
189 { |
|
190 if (!h) |
|
191 return E_POINTER; |
|
192 *h = m_scrollBar->height(); |
|
193 return S_OK; |
|
194 } |
|
195 |
|
196 HRESULT STDMETHODCALLTYPE WebScrollBar::requestedWidth( |
|
197 /* [retval][out] */ int* w) |
|
198 { |
|
199 if (!w) |
|
200 return E_POINTER; |
|
201 |
|
202 *w = m_scrollBar->orientation() == VerticalScrollbar ? PlatformScrollbar::verticalScrollbarWidth(m_scrollBar->controlSize()) : -1; |
|
203 return S_OK; |
|
204 } |
|
205 |
|
206 HRESULT STDMETHODCALLTYPE WebScrollBar::requestedHeight( |
|
207 /* [retval][out] */ int* h) |
|
208 { |
|
209 if (!h) |
|
210 return E_POINTER; |
|
211 |
|
212 *h = m_scrollBar->orientation() == HorizontalScrollbar ? PlatformScrollbar::horizontalScrollbarHeight(m_scrollBar->controlSize()) : -1; |
|
213 return S_OK; |
|
214 } |
|
215 |
|
216 |
|
217 HRESULT STDMETHODCALLTYPE WebScrollBar::handleMouseEvent( |
|
218 OLE_HANDLE window, |
|
219 UINT msg, |
|
220 WPARAM wParam, |
|
221 LPARAM lParam) |
|
222 { |
|
223 PlatformMouseEvent mouseEvent((HWND)(ULONG64)window, msg, wParam, lParam); |
|
224 switch (msg) { |
|
225 case WM_LBUTTONDOWN: |
|
226 m_scrollBar->handleMousePressEvent(mouseEvent); |
|
227 break; |
|
228 case WM_LBUTTONUP: |
|
229 m_scrollBar->handleMouseReleaseEvent(mouseEvent); |
|
230 break; |
|
231 case WM_MOUSEMOVE: |
|
232 m_scrollBar->handleMouseMoveEvent(mouseEvent); |
|
233 break; |
|
234 } |
|
235 |
|
236 return S_OK; |
|
237 } |
|
238 |
|
239 HRESULT STDMETHODCALLTYPE WebScrollBar::scroll( |
|
240 WebScrollDirection direction, |
|
241 WebScrollGranularity granularity, |
|
242 float multiplier) |
|
243 { |
|
244 ScrollDirection webCoreScrollDirection = (ScrollDirection) direction; |
|
245 ScrollGranularity webCoreGranularity = (ScrollGranularity) granularity; |
|
246 m_scrollBar->scroll(webCoreScrollDirection, webCoreGranularity, multiplier); |
|
247 return S_OK; |
|
248 } |
|
249 |
|
250 // ScrollbarClient ------------------------------------------------------- |
|
251 void WebScrollBar::valueChanged(Scrollbar* scrollBar) |
|
252 { |
|
253 if (m_scrollBar != scrollBar) { |
|
254 ASSERT(false); // shouldn't happen |
|
255 return; |
|
256 } |
|
257 m_delegate->valueChanged(this); |
|
258 } |
|
259 |
|
260 IntRect WebScrollBar::windowClipRect() const |
|
261 { |
|
262 HWND sbContainingWindow = m_scrollBar->containingWindow(); |
|
263 RECT clientRect; |
|
264 ::GetClientRect(sbContainingWindow, &clientRect); |
|
265 return IntRect(clientRect.left, clientRect.top, clientRect.right-clientRect.left, clientRect.bottom-clientRect.top); |
|
266 } |