| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "WebScrollbarImpl.h" | 32 #include "WebScrollbarImpl.h" |
| 33 | 33 |
| 34 #include "GraphicsContext.h" | 34 #include "GraphicsContext.h" |
| 35 #include "KeyboardCodes.h" | 35 #include "KeyboardCodes.h" |
| 36 #include "painting/GraphicsContextBuilder.h" | 36 #include "painting/GraphicsContextBuilder.h" |
| 37 #include "ScrollAnimator.h" |
| 37 #include "Scrollbar.h" | 38 #include "Scrollbar.h" |
| 39 #include "ScrollbarGroup.h" |
| 38 #include "ScrollbarTheme.h" | 40 #include "ScrollbarTheme.h" |
| 39 #include "ScrollTypes.h" | 41 #include "ScrollTypes.h" |
| 40 #include "WebCanvas.h" | 42 #include "WebCanvas.h" |
| 41 #include "WebInputEvent.h" | 43 #include "WebInputEvent.h" |
| 42 #include "WebInputEventConversion.h" | 44 #include "WebInputEventConversion.h" |
| 45 #include "WebPluginContainerImpl.h" |
| 43 #include "WebRect.h" | 46 #include "WebRect.h" |
| 44 #include "WebScrollbarClient.h" | 47 #include "WebScrollbarClient.h" |
| 45 #include "WebVector.h" | 48 #include "WebVector.h" |
| 46 #include "WebViewImpl.h" | 49 #include "WebViewImpl.h" |
| 47 | 50 |
| 48 using namespace std; | 51 using namespace std; |
| 49 using namespace WebCore; | 52 using namespace WebCore; |
| 50 | 53 |
| 51 namespace WebKit { | 54 namespace WebKit { |
| 52 | 55 |
| 53 WebScrollbar* WebScrollbar::create(WebScrollbarClient* client, Orientation orien
tation) | 56 WebScrollbar* WebScrollbar::create(Orientation orientation, |
| 57 WebPluginContainer* pluginContainer, |
| 58 WebScrollbarClient* client) |
| 54 { | 59 { |
| 55 return new WebScrollbarImpl(client, orientation); | 60 WebPluginContainerImpl* plugin = static_cast<WebPluginContainerImpl*>(plugin
Container); |
| 61 return new WebScrollbarImpl(orientation, plugin->scrollbarGroup(), client); |
| 56 } | 62 } |
| 57 | 63 |
| 58 int WebScrollbar::defaultThickness() | 64 int WebScrollbar::defaultThickness() |
| 59 { | 65 { |
| 60 return ScrollbarTheme::nativeTheme()->scrollbarThickness(); | 66 return ScrollbarTheme::nativeTheme()->scrollbarThickness(); |
| 61 } | 67 } |
| 62 | 68 |
| 63 WebScrollbarImpl::WebScrollbarImpl(WebScrollbarClient* client, Orientation orien
tation) | 69 WebScrollbarImpl::WebScrollbarImpl(Orientation orientation, |
| 64 : m_client(client) | 70 ScrollbarGroup* group, |
| 71 WebScrollbarClient* client) |
| 72 : m_group(group) |
| 73 , m_client(client) |
| 65 , m_scrollOffset(0) | 74 , m_scrollOffset(0) |
| 66 { | 75 { |
| 67 m_scrollbar = Scrollbar::createNativeScrollbar( | 76 m_scrollbar = Scrollbar::createNativeScrollbar( |
| 68 static_cast<ScrollableArea*>(this), | 77 static_cast<ScrollableArea*>(m_group), |
| 69 static_cast<ScrollbarOrientation>(orientation), | 78 static_cast<ScrollbarOrientation>(orientation), |
| 70 RegularScrollbar); | 79 RegularScrollbar); |
| 80 m_group->scrollbarCreated(this); |
| 71 } | 81 } |
| 72 | 82 |
| 73 WebScrollbarImpl::~WebScrollbarImpl() | 83 WebScrollbarImpl::~WebScrollbarImpl() |
| 74 { | 84 { |
| 85 m_group->scrollbarDestroyed(this); |
| 86 } |
| 87 |
| 88 void WebScrollbarImpl::setScrollOffset(int scrollOffset) |
| 89 { |
| 90 m_scrollOffset = scrollOffset; |
| 91 m_client->valueChanged(this); |
| 92 } |
| 93 |
| 94 void WebScrollbarImpl::invalidateScrollbarRect(const IntRect& rect) |
| 95 { |
| 96 WebRect webrect(rect); |
| 97 webrect.x += m_scrollbar->x(); |
| 98 webrect.y += m_scrollbar->y(); |
| 99 m_client->invalidateScrollbarRect(this, webrect); |
| 100 } |
| 101 |
| 102 void WebScrollbarImpl::getTickmarks(Vector<IntRect>& tickmarks) const |
| 103 { |
| 104 WebVector<WebRect> ticks; |
| 105 m_client->getTickmarks(const_cast<WebScrollbarImpl*>(this), &ticks); |
| 106 tickmarks.resize(ticks.size()); |
| 107 for (size_t i = 0; i < ticks.size(); ++i) |
| 108 tickmarks[i] = ticks[i]; |
| 109 } |
| 110 |
| 111 IntPoint WebScrollbarImpl::convertFromContainingViewToScrollbar(const IntPoint&
parentPoint) const |
| 112 { |
| 113 IntPoint offset(parentPoint.x() - m_scrollbar->x(), parentPoint.y() - m_scro
llbar->y()); |
| 114 return m_scrollbar->Widget::convertFromContainingView(offset); |
| 115 } |
| 116 |
| 117 void WebScrollbarImpl::scrollbarStyleChanged() |
| 118 { |
| 119 m_client->overlayChanged(this); |
| 120 } |
| 121 |
| 122 bool WebScrollbarImpl::isOverlay() |
| 123 { |
| 124 return m_scrollbar->isOverlayScrollbar(); |
| 75 } | 125 } |
| 76 | 126 |
| 77 void WebScrollbarImpl::setLocation(const WebRect& rect) | 127 void WebScrollbarImpl::setLocation(const WebRect& rect) |
| 78 { | 128 { |
| 79 IntRect oldRect = m_scrollbar->frameRect(); | 129 IntRect oldRect = m_scrollbar->frameRect(); |
| 80 m_scrollbar->setFrameRect(rect); | 130 m_scrollbar->setFrameRect(rect); |
| 81 if (WebRect(oldRect) != rect) | 131 if (WebRect(oldRect) != rect) |
| 82 m_scrollbar->invalidate(); | 132 m_scrollbar->invalidate(); |
| 83 | 133 |
| 84 int length = m_scrollbar->orientation() == HorizontalScrollbar ? m_scrollbar
->width() : m_scrollbar->height(); | 134 int length = m_scrollbar->orientation() == HorizontalScrollbar ? m_scrollbar
->width() : m_scrollbar->height(); |
| 85 int pageStep = max(max(static_cast<int>(static_cast<float>(length) * Scrollb
ar::minFractionToStepWhenPaging()), length - Scrollbar::maxOverlapBetweenPages()
), 1); | 135 int pageStep = max(max(static_cast<int>(static_cast<float>(length) * Scrollb
ar::minFractionToStepWhenPaging()), length - Scrollbar::maxOverlapBetweenPages()
), 1); |
| 86 m_scrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); | 136 m_scrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); |
| 87 m_scrollbar->setEnabled(m_scrollbar->totalSize() > length); | 137 m_scrollbar->setEnabled(m_scrollbar->totalSize() > length); |
| 88 m_scrollbar->setProportion(length, m_scrollbar->totalSize()); | 138 m_scrollbar->setProportion(length, m_scrollbar->totalSize()); |
| 89 } | 139 } |
| 90 | 140 |
| 91 int WebScrollbarImpl::value() const | 141 int WebScrollbarImpl::value() const |
| 92 { | 142 { |
| 93 return m_scrollOffset; | 143 return m_scrollOffset; |
| 94 } | 144 } |
| 95 | 145 |
| 96 void WebScrollbarImpl::setValue(int position) | 146 void WebScrollbarImpl::setValue(int position) |
| 97 { | 147 { |
| 98 ScrollableArea::scrollToOffsetWithoutAnimation(m_scrollbar->orientation(), s
tatic_cast<float>(position)); | 148 m_group->scrollToOffsetWithoutAnimation(m_scrollbar->orientation(), static_c
ast<float>(position)); |
| 99 } | 149 } |
| 100 | 150 |
| 101 void WebScrollbarImpl::setDocumentSize(int size) | 151 void WebScrollbarImpl::setDocumentSize(int size) |
| 102 { | 152 { |
| 103 int length = m_scrollbar->orientation() == HorizontalScrollbar ? m_scrollbar
->width() : m_scrollbar->height(); | 153 int length = m_scrollbar->orientation() == HorizontalScrollbar ? m_scrollbar
->width() : m_scrollbar->height(); |
| 104 m_scrollbar->setEnabled(size > length); | 154 m_scrollbar->setEnabled(size > length); |
| 105 m_scrollbar->setProportion(length, size); | 155 m_scrollbar->setProportion(length, size); |
| 106 } | 156 } |
| 107 | 157 |
| 108 void WebScrollbarImpl::scroll(ScrollDirection direction, ScrollGranularity granu
larity, float multiplier) | 158 void WebScrollbarImpl::scroll(ScrollDirection direction, ScrollGranularity granu
larity, float multiplier) |
| 109 { | 159 { |
| 110 WebCore::ScrollDirection dir; | 160 WebCore::ScrollDirection dir; |
| 111 bool horizontal = m_scrollbar->orientation() == HorizontalScrollbar; | 161 bool horizontal = m_scrollbar->orientation() == HorizontalScrollbar; |
| 112 if (direction == ScrollForward) | 162 if (direction == ScrollForward) |
| 113 dir = horizontal ? ScrollRight : ScrollDown; | 163 dir = horizontal ? ScrollRight : ScrollDown; |
| 114 else | 164 else |
| 115 dir = horizontal ? ScrollLeft : ScrollUp; | 165 dir = horizontal ? ScrollLeft : ScrollUp; |
| 116 | 166 |
| 117 WebCore::ScrollableArea::scroll(dir, static_cast<WebCore::ScrollGranularity>
(granularity), multiplier); | 167 m_group->scroll(dir, static_cast<WebCore::ScrollGranularity>(granularity), m
ultiplier); |
| 118 } | 168 } |
| 119 | 169 |
| 120 void WebScrollbarImpl::paint(WebCanvas* canvas, const WebRect& rect) | 170 void WebScrollbarImpl::paint(WebCanvas* canvas, const WebRect& rect) |
| 121 { | 171 { |
| 122 m_scrollbar->paint(&GraphicsContextBuilder(canvas).context(), rect); | 172 m_scrollbar->paint(&GraphicsContextBuilder(canvas).context(), rect); |
| 123 } | 173 } |
| 124 | 174 |
| 125 bool WebScrollbarImpl::handleInputEvent(const WebInputEvent& event) | 175 bool WebScrollbarImpl::handleInputEvent(const WebInputEvent& event) |
| 126 { | 176 { |
| 127 switch (event.type) { | 177 switch (event.type) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 bool WebScrollbarImpl::onMouseMove(const WebInputEvent& event) | 225 bool WebScrollbarImpl::onMouseMove(const WebInputEvent& event) |
| 176 { | 226 { |
| 177 WebMouseEvent mousemove = *static_cast<const WebMouseEvent*>(&event); | 227 WebMouseEvent mousemove = *static_cast<const WebMouseEvent*>(&event); |
| 178 if (m_scrollbar->frameRect().contains(mousemove.x, mousemove.y) | 228 if (m_scrollbar->frameRect().contains(mousemove.x, mousemove.y) |
| 179 || m_scrollbar->pressedPart() != NoPart) { | 229 || m_scrollbar->pressedPart() != NoPart) { |
| 180 mousemove.x -= m_scrollbar->x(); | 230 mousemove.x -= m_scrollbar->x(); |
| 181 mousemove.y -= m_scrollbar->y(); | 231 mousemove.y -= m_scrollbar->y(); |
| 182 return m_scrollbar->mouseMoved(PlatformMouseEventBuilder(m_scrollbar.get
(), mousemove)); | 232 return m_scrollbar->mouseMoved(PlatformMouseEventBuilder(m_scrollbar.get
(), mousemove)); |
| 183 } | 233 } |
| 184 | 234 |
| 185 if (m_scrollbar->hoveredPart() != NoPart) | 235 if (m_scrollbar->hoveredPart() != NoPart && !m_scrollbar->isOverlayScrollbar
()) |
| 186 m_scrollbar->mouseExited(); | 236 m_scrollbar->mouseExited(); |
| 187 return false; | 237 return false; |
| 188 } | 238 } |
| 189 | 239 |
| 190 bool WebScrollbarImpl::onMouseLeave(const WebInputEvent& event) | 240 bool WebScrollbarImpl::onMouseLeave(const WebInputEvent& event) |
| 191 { | 241 { |
| 192 if (m_scrollbar->hoveredPart() == NoPart) | 242 if (m_scrollbar->hoveredPart() != NoPart) |
| 193 return false; | 243 m_scrollbar->mouseExited(); |
| 194 | 244 |
| 195 return m_scrollbar->mouseExited(); | 245 return false; |
| 196 } | 246 } |
| 197 | 247 |
| 198 bool WebScrollbarImpl::onMouseWheel(const WebInputEvent& event) | 248 bool WebScrollbarImpl::onMouseWheel(const WebInputEvent& event) |
| 199 { | 249 { |
| 200 // Same logic as in Scrollview.cpp. If we can move at all, we'll accept the
event. | |
| 201 WebMouseWheelEvent mousewheel = *static_cast<const WebMouseWheelEvent*>(&eve
nt); | 250 WebMouseWheelEvent mousewheel = *static_cast<const WebMouseWheelEvent*>(&eve
nt); |
| 202 int maxScrollDelta = m_scrollbar->maximum() - m_scrollbar->value(); | 251 PlatformWheelEventBuilder platformEvent(m_scrollbar.get(), mousewheel); |
| 203 float delta = m_scrollbar->orientation() == HorizontalScrollbar ? mousewheel
.deltaX : mousewheel.deltaY; | 252 m_group->handleWheelEvent(platformEvent); |
| 204 if ((delta < 0 && maxScrollDelta > 0) || (delta > 0 && m_scrollbar->value()
> 0)) { | 253 return platformEvent.isAccepted(); |
| 205 if (mousewheel.scrollByPage) { | 254 } |
| 206 ASSERT(m_scrollbar->orientation() == VerticalScrollbar); | |
| 207 bool negative = delta < 0; | |
| 208 delta = max(max(static_cast<float>(m_scrollbar->visibleSize()) * Scr
ollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollbar->visibleSi
ze() - Scrollbar::maxOverlapBetweenPages())), 1.0f); | |
| 209 if (negative) | |
| 210 delta *= -1; | |
| 211 } | |
| 212 ScrollableArea::scroll((m_scrollbar->orientation() == HorizontalScrollba
r) ? WebCore::ScrollLeft : WebCore::ScrollUp, WebCore::ScrollByPixel, delta); | |
| 213 return true; | |
| 214 } | |
| 215 | |
| 216 return false; | |
| 217 } | |
| 218 | 255 |
| 219 bool WebScrollbarImpl::onKeyDown(const WebInputEvent& event) | 256 bool WebScrollbarImpl::onKeyDown(const WebInputEvent& event) |
| 220 { | 257 { |
| 221 WebKeyboardEvent keyboard = *static_cast<const WebKeyboardEvent*>(&event); | 258 WebKeyboardEvent keyboard = *static_cast<const WebKeyboardEvent*>(&event); |
| 222 int keyCode; | 259 int keyCode; |
| 223 // We have to duplicate this logic from WebViewImpl because there it uses | 260 // We have to duplicate this logic from WebViewImpl because there it uses |
| 224 // Char and RawKeyDown events, which don't exist at this point. | 261 // Char and RawKeyDown events, which don't exist at this point. |
| 225 if (keyboard.windowsKeyCode == VKEY_SPACE) | 262 if (keyboard.windowsKeyCode == VKEY_SPACE) |
| 226 keyCode = ((keyboard.modifiers & WebInputEvent::ShiftKey) ? VKEY_PRIOR :
VKEY_NEXT); | 263 keyCode = ((keyboard.modifiers & WebInputEvent::ShiftKey) ? VKEY_PRIOR :
VKEY_NEXT); |
| 227 else { | 264 else { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 241 | 278 |
| 242 if (keyboard.isSystemKey || (keyboard.modifiers & WebInputEvent::ShiftKe
y)) | 279 if (keyboard.isSystemKey || (keyboard.modifiers & WebInputEvent::ShiftKe
y)) |
| 243 return false; | 280 return false; |
| 244 | 281 |
| 245 keyCode = keyboard.windowsKeyCode; | 282 keyCode = keyboard.windowsKeyCode; |
| 246 } | 283 } |
| 247 WebCore::ScrollDirection scrollDirection; | 284 WebCore::ScrollDirection scrollDirection; |
| 248 WebCore::ScrollGranularity scrollGranularity; | 285 WebCore::ScrollGranularity scrollGranularity; |
| 249 if (WebViewImpl::mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranu
larity)) { | 286 if (WebViewImpl::mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranu
larity)) { |
| 250 // Will return false if scroll direction wasn't compatible with this scr
ollbar. | 287 // Will return false if scroll direction wasn't compatible with this scr
ollbar. |
| 251 return ScrollableArea::scroll(scrollDirection, scrollGranularity); | 288 return m_group->scroll(scrollDirection, scrollGranularity); |
| 252 } | 289 } |
| 253 return false; | 290 return false; |
| 254 } | 291 } |
| 255 | 292 |
| 256 int WebScrollbarImpl::scrollSize(WebCore::ScrollbarOrientation orientation) cons
t | |
| 257 { | |
| 258 return (orientation == m_scrollbar->orientation()) ? (m_scrollbar->totalSize
() - m_scrollbar->visibleSize()) : 0; | |
| 259 } | |
| 260 | |
| 261 int WebScrollbarImpl::scrollPosition(Scrollbar*) const | |
| 262 { | |
| 263 return m_scrollOffset; | |
| 264 } | |
| 265 | |
| 266 void WebScrollbarImpl::setScrollOffset(const IntPoint& offset) | |
| 267 { | |
| 268 if (m_scrollbar->orientation() == HorizontalScrollbar) | |
| 269 m_scrollOffset = offset.x(); | |
| 270 else | |
| 271 m_scrollOffset = offset.y(); | |
| 272 | |
| 273 m_client->valueChanged(this); | |
| 274 } | |
| 275 | |
| 276 void WebScrollbarImpl::invalidateScrollbarRect(Scrollbar*, const IntRect& rect) | |
| 277 { | |
| 278 WebRect webrect(rect); | |
| 279 webrect.x += m_scrollbar->x(); | |
| 280 webrect.y += m_scrollbar->y(); | |
| 281 m_client->invalidateScrollbarRect(this, webrect); | |
| 282 } | |
| 283 | |
| 284 void WebScrollbarImpl::invalidateScrollCornerRect(const IntRect&) | |
| 285 { | |
| 286 } | |
| 287 | |
| 288 bool WebScrollbarImpl::isActive() const | |
| 289 { | |
| 290 return true; | |
| 291 } | |
| 292 | |
| 293 ScrollableArea* WebScrollbarImpl::enclosingScrollableArea() const | |
| 294 { | |
| 295 // FIXME: Return a parent scrollable area that can be scrolled. | |
| 296 return 0; | |
| 297 } | |
| 298 | |
| 299 bool WebScrollbarImpl::isScrollCornerVisible() const | |
| 300 { | |
| 301 return false; | |
| 302 } | |
| 303 | |
| 304 void WebScrollbarImpl::getTickmarks(Vector<IntRect>& tickmarks) const | |
| 305 { | |
| 306 WebVector<WebRect> ticks; | |
| 307 m_client->getTickmarks(const_cast<WebScrollbarImpl*>(this), &ticks); | |
| 308 tickmarks.resize(ticks.size()); | |
| 309 for (size_t i = 0; i < ticks.size(); ++i) | |
| 310 tickmarks[i] = ticks[i]; | |
| 311 } | |
| 312 | |
| 313 Scrollbar* WebScrollbarImpl::horizontalScrollbar() const | |
| 314 { | |
| 315 return m_scrollbar->orientation() == HorizontalScrollbar ? m_scrollbar.get()
: 0; | |
| 316 } | |
| 317 | |
| 318 Scrollbar* WebScrollbarImpl::verticalScrollbar() const | |
| 319 { | |
| 320 return m_scrollbar->orientation() == VerticalScrollbar ? m_scrollbar.get() :
0; | |
| 321 } | |
| 322 | |
| 323 int WebScrollbarImpl::visibleHeight() const | |
| 324 { | |
| 325 return m_scrollbar->height(); | |
| 326 } | |
| 327 | |
| 328 int WebScrollbarImpl::visibleWidth() const | |
| 329 { | |
| 330 return m_scrollbar->width(); | |
| 331 } | |
| 332 | |
| 333 IntSize WebScrollbarImpl::contentsSize() const | |
| 334 { | |
| 335 // This isn't technically correct, since we don't have the contentSize. Howe
ver it's good enough | |
| 336 // to make the ScrollAnimator code happy. | |
| 337 int thickness = defaultThickness(); | |
| 338 int length = m_scrollbar->totalSize(); | |
| 339 return m_scrollbar->orientation() == VerticalScrollbar ? IntSize(thickness,
length) : IntSize(length, thickness); | |
| 340 } | |
| 341 | |
| 342 IntSize WebScrollbarImpl::overhangAmount() const | |
| 343 { | |
| 344 return IntSize(); | |
| 345 } | |
| 346 | |
| 347 } // namespace WebKit | 293 } // namespace WebKit |
| OLD | NEW |