| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Google 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 INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 23 */ | |
| 24 | |
| 25 #include "config.h" | |
| 26 #include "web/WebPluginScrollbarImpl.h" | |
| 27 | |
| 28 #include "platform/KeyboardCodes.h" | |
| 29 #include "platform/graphics/GraphicsContext.h" | |
| 30 #include "platform/scroll/ScrollAnimator.h" | |
| 31 #include "platform/scroll/ScrollTypes.h" | |
| 32 #include "platform/scroll/Scrollbar.h" | |
| 33 #include "platform/scroll/ScrollbarTheme.h" | |
| 34 #include "public/platform/WebCanvas.h" | |
| 35 #include "public/platform/WebRect.h" | |
| 36 #include "public/platform/WebVector.h" | |
| 37 #include "public/web/WebInputEvent.h" | |
| 38 #include "public/web/WebPluginScrollbarClient.h" | |
| 39 #include "web/ScrollbarGroup.h" | |
| 40 #include "web/WebInputEventConversion.h" | |
| 41 #include "web/WebPluginContainerImpl.h" | |
| 42 #include "web/WebViewImpl.h" | |
| 43 | |
| 44 namespace blink { | |
| 45 | |
| 46 WebPluginScrollbar* WebPluginScrollbar::createForPlugin(Orientation orientation, | |
| 47 WebPluginContainer* plug
inContainer, | |
| 48 WebPluginScrollbarClient
* client) | |
| 49 { | |
| 50 WebPluginContainerImpl* plugin = toWebPluginContainerImpl(pluginContainer); | |
| 51 return new WebPluginScrollbarImpl(orientation, plugin->scrollbarGroup(), cli
ent); | |
| 52 } | |
| 53 | |
| 54 int WebPluginScrollbar::defaultThickness() | |
| 55 { | |
| 56 return ScrollbarTheme::theme()->scrollbarThickness(); | |
| 57 } | |
| 58 | |
| 59 WebPluginScrollbarImpl::WebPluginScrollbarImpl(Orientation orientation, | |
| 60 ScrollbarGroup* group, | |
| 61 WebPluginScrollbarClient* client) | |
| 62 : m_group(group) | |
| 63 , m_client(client) | |
| 64 , m_scrollOffset(0) | |
| 65 { | |
| 66 m_scrollbar = Scrollbar::create( | |
| 67 static_cast<ScrollableArea*>(m_group), | |
| 68 static_cast<ScrollbarOrientation>(orientation), | |
| 69 blink::RegularScrollbar); | |
| 70 m_group->scrollbarCreated(this); | |
| 71 } | |
| 72 | |
| 73 WebPluginScrollbarImpl::~WebPluginScrollbarImpl() | |
| 74 { | |
| 75 m_group->scrollbarDestroyed(this); | |
| 76 } | |
| 77 | |
| 78 void WebPluginScrollbarImpl::setScrollOffset(int scrollOffset) | |
| 79 { | |
| 80 m_scrollOffset = scrollOffset; | |
| 81 m_client->valueChanged(this); | |
| 82 } | |
| 83 | |
| 84 void WebPluginScrollbarImpl::invalidateScrollbarRect(const IntRect& rect) | |
| 85 { | |
| 86 WebRect webrect(rect); | |
| 87 webrect.x += m_scrollbar->x(); | |
| 88 webrect.y += m_scrollbar->y(); | |
| 89 m_client->invalidateScrollbarRect(this, webrect); | |
| 90 } | |
| 91 | |
| 92 void WebPluginScrollbarImpl::getTickmarks(Vector<IntRect>& tickmarks) const | |
| 93 { | |
| 94 WebVector<WebRect> ticks; | |
| 95 m_client->getTickmarks(const_cast<WebPluginScrollbarImpl*>(this), &ticks); | |
| 96 tickmarks.resize(ticks.size()); | |
| 97 for (size_t i = 0; i < ticks.size(); ++i) | |
| 98 tickmarks[i] = ticks[i]; | |
| 99 } | |
| 100 | |
| 101 IntPoint WebPluginScrollbarImpl::convertFromContainingViewToScrollbar(const IntP
oint& parentPoint) const | |
| 102 { | |
| 103 IntPoint offset(parentPoint.x() - m_scrollbar->x(), parentPoint.y() - m_scro
llbar->y()); | |
| 104 return m_scrollbar->Widget::convertFromContainingView(offset); | |
| 105 } | |
| 106 | |
| 107 void WebPluginScrollbarImpl::scrollbarStyleChanged() | |
| 108 { | |
| 109 m_client->overlayChanged(this); | |
| 110 } | |
| 111 | |
| 112 bool WebPluginScrollbarImpl::isOverlay() const | |
| 113 { | |
| 114 return m_scrollbar->isOverlayScrollbar(); | |
| 115 } | |
| 116 | |
| 117 int WebPluginScrollbarImpl::value() const | |
| 118 { | |
| 119 return m_scrollOffset; | |
| 120 } | |
| 121 | |
| 122 WebPoint WebPluginScrollbarImpl::location() const | |
| 123 { | |
| 124 return m_scrollbar->frameRect().location(); | |
| 125 } | |
| 126 | |
| 127 WebSize WebPluginScrollbarImpl::size() const | |
| 128 { | |
| 129 return m_scrollbar->frameRect().size(); | |
| 130 } | |
| 131 | |
| 132 bool WebPluginScrollbarImpl::enabled() const | |
| 133 { | |
| 134 return m_scrollbar->enabled(); | |
| 135 } | |
| 136 | |
| 137 int WebPluginScrollbarImpl::maximum() const | |
| 138 { | |
| 139 return m_scrollbar->maximum(); | |
| 140 } | |
| 141 | |
| 142 int WebPluginScrollbarImpl::totalSize() const | |
| 143 { | |
| 144 return m_scrollbar->totalSize(); | |
| 145 } | |
| 146 | |
| 147 bool WebPluginScrollbarImpl::isScrollableAreaActive() const | |
| 148 { | |
| 149 return m_scrollbar->isScrollableAreaActive(); | |
| 150 } | |
| 151 | |
| 152 void WebPluginScrollbarImpl::getTickmarks(WebVector<WebRect>& tickmarks) const | |
| 153 { | |
| 154 m_client->getTickmarks(const_cast<WebPluginScrollbarImpl*>(this), &tickmarks
); | |
| 155 } | |
| 156 | |
| 157 WebScrollbar::ScrollbarControlSize WebPluginScrollbarImpl::controlSize() const | |
| 158 { | |
| 159 return static_cast<WebScrollbar::ScrollbarControlSize>(m_scrollbar->controlS
ize()); | |
| 160 } | |
| 161 | |
| 162 WebScrollbar::ScrollbarPart WebPluginScrollbarImpl::pressedPart() const | |
| 163 { | |
| 164 return static_cast<WebScrollbar::ScrollbarPart>(m_scrollbar->pressedPart()); | |
| 165 } | |
| 166 | |
| 167 WebScrollbar::ScrollbarPart WebPluginScrollbarImpl::hoveredPart() const | |
| 168 { | |
| 169 return static_cast<WebScrollbar::ScrollbarPart>(m_scrollbar->hoveredPart()); | |
| 170 } | |
| 171 | |
| 172 WebScrollbar::ScrollbarOverlayStyle WebPluginScrollbarImpl::scrollbarOverlayStyl
e() const | |
| 173 { | |
| 174 return static_cast<WebScrollbar::ScrollbarOverlayStyle>(m_scrollbar->scrollb
arOverlayStyle()); | |
| 175 } | |
| 176 | |
| 177 WebScrollbar::Orientation WebPluginScrollbarImpl::orientation() const | |
| 178 { | |
| 179 if (m_scrollbar->orientation() == HorizontalScrollbar) | |
| 180 return WebScrollbar::Horizontal; | |
| 181 return WebScrollbar::Vertical; | |
| 182 } | |
| 183 | |
| 184 bool WebPluginScrollbarImpl::isLeftSideVerticalScrollbar() const | |
| 185 { | |
| 186 return false; | |
| 187 } | |
| 188 | |
| 189 bool WebPluginScrollbarImpl::isCustomScrollbar() const | |
| 190 { | |
| 191 return m_scrollbar->isCustomScrollbar(); | |
| 192 } | |
| 193 | |
| 194 void WebPluginScrollbarImpl::setLocation(const WebRect& rect) | |
| 195 { | |
| 196 IntRect oldRect = m_scrollbar->frameRect(); | |
| 197 m_scrollbar->setFrameRect(rect); | |
| 198 if (WebRect(oldRect) != rect) | |
| 199 m_scrollbar->invalidate(); | |
| 200 | |
| 201 int length = m_scrollbar->orientation() == HorizontalScrollbar ? m_scrollbar
->width() : m_scrollbar->height(); | |
| 202 m_scrollbar->setEnabled(m_scrollbar->totalSize() > length); | |
| 203 m_scrollbar->setProportion(length, m_scrollbar->totalSize()); | |
| 204 } | |
| 205 | |
| 206 void WebPluginScrollbarImpl::setValue(int position) | |
| 207 { | |
| 208 m_group->scrollToOffsetWithoutAnimation(m_scrollbar->orientation(), static_c
ast<float>(position)); | |
| 209 } | |
| 210 | |
| 211 void WebPluginScrollbarImpl::setDocumentSize(int size) | |
| 212 { | |
| 213 int length = m_scrollbar->orientation() == HorizontalScrollbar ? m_scrollbar
->width() : m_scrollbar->height(); | |
| 214 m_scrollbar->setEnabled(size > length); | |
| 215 m_scrollbar->setProportion(length, size); | |
| 216 } | |
| 217 | |
| 218 void WebPluginScrollbarImpl::scroll(ScrollDirection direction, ScrollGranularity
granularity, float multiplier) | |
| 219 { | |
| 220 blink::ScrollDirectionPhysical dir; | |
| 221 bool horizontal = m_scrollbar->orientation() == HorizontalScrollbar; | |
| 222 if (direction == ScrollForward) | |
| 223 dir = horizontal ? ScrollRight : ScrollDown; | |
| 224 else | |
| 225 dir = horizontal ? ScrollLeft : ScrollUp; | |
| 226 | |
| 227 m_group->scroll(dir, static_cast<blink::ScrollGranularity>(granularity), mul
tiplier); | |
| 228 } | |
| 229 | |
| 230 void WebPluginScrollbarImpl::paint(WebCanvas* canvas, const WebRect& rect) | |
| 231 { | |
| 232 OwnPtr<GraphicsContext> context = GraphicsContext::deprecatedCreateWithCanva
s(canvas); | |
| 233 m_scrollbar->paint(context.get(), rect); | |
| 234 } | |
| 235 | |
| 236 bool WebPluginScrollbarImpl::handleInputEvent(const WebInputEvent& event) | |
| 237 { | |
| 238 switch (event.type) { | |
| 239 case WebInputEvent::MouseDown: | |
| 240 return onMouseDown(event); | |
| 241 case WebInputEvent::MouseUp: | |
| 242 return onMouseUp(event); | |
| 243 case WebInputEvent::MouseMove: | |
| 244 return onMouseMove(event); | |
| 245 case WebInputEvent::MouseLeave: | |
| 246 return onMouseLeave(event); | |
| 247 case WebInputEvent::MouseWheel: | |
| 248 return onMouseWheel(event); | |
| 249 case WebInputEvent::KeyDown: | |
| 250 return onKeyDown(event); | |
| 251 case WebInputEvent::Undefined: | |
| 252 case WebInputEvent::MouseEnter: | |
| 253 case WebInputEvent::RawKeyDown: | |
| 254 case WebInputEvent::KeyUp: | |
| 255 case WebInputEvent::Char: | |
| 256 case WebInputEvent::TouchStart: | |
| 257 case WebInputEvent::TouchMove: | |
| 258 case WebInputEvent::TouchEnd: | |
| 259 case WebInputEvent::TouchCancel: | |
| 260 default: | |
| 261 break; | |
| 262 } | |
| 263 return false; | |
| 264 } | |
| 265 | |
| 266 bool WebPluginScrollbarImpl::isAlphaLocked() const | |
| 267 { | |
| 268 return m_scrollbar->isAlphaLocked(); | |
| 269 } | |
| 270 | |
| 271 void WebPluginScrollbarImpl::setIsAlphaLocked(bool flag) | |
| 272 { | |
| 273 return m_scrollbar->setIsAlphaLocked(flag); | |
| 274 } | |
| 275 | |
| 276 bool WebPluginScrollbarImpl::onMouseDown(const WebInputEvent& event) | |
| 277 { | |
| 278 WebMouseEvent mousedown = static_cast<const WebMouseEvent&>(event); | |
| 279 if (!m_scrollbar->frameRect().contains(mousedown.x, mousedown.y)) | |
| 280 return false; | |
| 281 | |
| 282 mousedown.x -= m_scrollbar->x(); | |
| 283 mousedown.y -= m_scrollbar->y(); | |
| 284 m_scrollbar->mouseDown(PlatformMouseEventBuilder(m_scrollbar.get(), mousedow
n)); | |
| 285 return true; | |
| 286 } | |
| 287 | |
| 288 bool WebPluginScrollbarImpl::onMouseUp(const WebInputEvent& event) | |
| 289 { | |
| 290 WebMouseEvent mouseup = static_cast<const WebMouseEvent&>(event); | |
| 291 if (m_scrollbar->pressedPart() == blink::NoPart) | |
| 292 return false; | |
| 293 | |
| 294 m_scrollbar->mouseUp(PlatformMouseEventBuilder(m_scrollbar.get(), mouseup)); | |
| 295 return true; | |
| 296 } | |
| 297 | |
| 298 bool WebPluginScrollbarImpl::onMouseMove(const WebInputEvent& event) | |
| 299 { | |
| 300 WebMouseEvent mousemove = static_cast<const WebMouseEvent&>(event); | |
| 301 if (m_scrollbar->frameRect().contains(mousemove.x, mousemove.y) | |
| 302 || m_scrollbar->pressedPart() != blink::NoPart) { | |
| 303 mousemove.x -= m_scrollbar->x(); | |
| 304 mousemove.y -= m_scrollbar->y(); | |
| 305 m_scrollbar->mouseMoved(PlatformMouseEventBuilder(m_scrollbar.get(), mou
semove)); | |
| 306 return true; | |
| 307 } | |
| 308 | |
| 309 if (m_scrollbar->hoveredPart() != blink::NoPart && !m_scrollbar->isOverlaySc
rollbar()) | |
| 310 m_scrollbar->mouseExited(); | |
| 311 return false; | |
| 312 } | |
| 313 | |
| 314 bool WebPluginScrollbarImpl::onMouseLeave(const WebInputEvent& event) | |
| 315 { | |
| 316 if (m_scrollbar->hoveredPart() != blink::NoPart) | |
| 317 m_scrollbar->mouseExited(); | |
| 318 | |
| 319 return false; | |
| 320 } | |
| 321 | |
| 322 bool WebPluginScrollbarImpl::onMouseWheel(const WebInputEvent& event) | |
| 323 { | |
| 324 WebMouseWheelEvent mousewheel = static_cast<const WebMouseWheelEvent&>(event
); | |
| 325 PlatformWheelEventBuilder platformEvent(m_scrollbar.get(), mousewheel); | |
| 326 return m_group->handleWheel(platformEvent).didScroll; | |
| 327 } | |
| 328 | |
| 329 bool WebPluginScrollbarImpl::onKeyDown(const WebInputEvent& event) | |
| 330 { | |
| 331 WebKeyboardEvent keyboard = static_cast<const WebKeyboardEvent&>(event); | |
| 332 int keyCode; | |
| 333 // We have to duplicate this logic from WebViewImpl because there it uses | |
| 334 // Char and RawKeyDown events, which don't exist at this point. | |
| 335 if (keyboard.windowsKeyCode == VKEY_SPACE) | |
| 336 keyCode = ((keyboard.modifiers & WebInputEvent::ShiftKey) ? VKEY_PRIOR :
VKEY_NEXT); | |
| 337 else { | |
| 338 if (keyboard.modifiers == WebInputEvent::ControlKey) { | |
| 339 // Match FF behavior in the sense that Ctrl+home/end are the only Ct
rl | |
| 340 // key combinations which affect scrolling. Safari is buggy in the | |
| 341 // sense that it scrolls the page for all Ctrl+scrolling key | |
| 342 // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc. | |
| 343 switch (keyboard.windowsKeyCode) { | |
| 344 case VKEY_HOME: | |
| 345 case VKEY_END: | |
| 346 break; | |
| 347 default: | |
| 348 return false; | |
| 349 } | |
| 350 } | |
| 351 | |
| 352 if (keyboard.isSystemKey || (keyboard.modifiers & WebInputEvent::ShiftKe
y)) | |
| 353 return false; | |
| 354 | |
| 355 keyCode = keyboard.windowsKeyCode; | |
| 356 } | |
| 357 blink::ScrollDirectionPhysical scrollDirection; | |
| 358 blink::ScrollGranularity scrollGranularity; | |
| 359 if (WebViewImpl::mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranu
larity)) { | |
| 360 // Will return false if scroll direction wasn't compatible with this scr
ollbar. | |
| 361 return m_group->scroll(scrollDirection, scrollGranularity); | |
| 362 } | |
| 363 return false; | |
| 364 } | |
| 365 | |
| 366 float WebPluginScrollbarImpl::elasticOverscroll() const | |
| 367 { | |
| 368 return m_scrollbar->elasticOverscroll(); | |
| 369 } | |
| 370 | |
| 371 void WebPluginScrollbarImpl::setElasticOverscroll(float elasticOverscroll) | |
| 372 { | |
| 373 m_scrollbar->setElasticOverscroll(elasticOverscroll); | |
| 374 } | |
| 375 | |
| 376 } // namespace blink | |
| OLD | NEW |