| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 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 are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "web/WebPopupMenuImpl.h" | |
| 33 | |
| 34 #include "core/frame/FrameView.h" | |
| 35 #include "platform/Cursor.h" | |
| 36 #include "platform/NotImplemented.h" | |
| 37 #include "platform/PlatformGestureEvent.h" | |
| 38 #include "platform/PlatformKeyboardEvent.h" | |
| 39 #include "platform/PlatformMouseEvent.h" | |
| 40 #include "platform/PlatformWheelEvent.h" | |
| 41 #include "platform/geometry/IntRect.h" | |
| 42 #include "platform/graphics/GraphicsContext.h" | |
| 43 #include "platform/graphics/skia/SkiaUtils.h" | |
| 44 #include "public/platform/Platform.h" | |
| 45 #include "public/platform/WebCompositorSupport.h" | |
| 46 #include "public/platform/WebContentLayer.h" | |
| 47 #include "public/platform/WebFloatRect.h" | |
| 48 #include "public/platform/WebLayerTreeView.h" | |
| 49 #include "public/platform/WebRect.h" | |
| 50 #include "public/web/WebInputEvent.h" | |
| 51 #include "public/web/WebRange.h" | |
| 52 #include "public/web/WebViewClient.h" | |
| 53 #include "public/web/WebWidgetClient.h" | |
| 54 #include "web/PopupContainer.h" | |
| 55 #include "web/PopupMenuChromium.h" | |
| 56 #include "web/WebInputEventConversion.h" | |
| 57 #include <skia/ext/platform_canvas.h> | |
| 58 | |
| 59 namespace blink { | |
| 60 | |
| 61 // WebPopupMenu --------------------------------------------------------------- | |
| 62 | |
| 63 WebPopupMenu* WebPopupMenu::create(WebWidgetClient* client) | |
| 64 { | |
| 65 // Pass the WebPopupMenuImpl's self-reference to the caller. | |
| 66 return adoptRef(new WebPopupMenuImpl(client)).leakRef(); | |
| 67 } | |
| 68 | |
| 69 // WebWidget ------------------------------------------------------------------ | |
| 70 | |
| 71 WebPopupMenuImpl::WebPopupMenuImpl(WebWidgetClient* client) | |
| 72 : m_client(client) | |
| 73 , m_layerTreeView(0) | |
| 74 // Set to impossible point so we always get the first mouse position. | |
| 75 , m_lastMousePosition(WebPoint(-1, -1)) | |
| 76 , m_widget(0) | |
| 77 { | |
| 78 } | |
| 79 | |
| 80 WebPopupMenuImpl::~WebPopupMenuImpl() | |
| 81 { | |
| 82 if (m_widget) | |
| 83 m_widget->setClient(0); | |
| 84 } | |
| 85 | |
| 86 void WebPopupMenuImpl::willCloseLayerTreeView() | |
| 87 { | |
| 88 m_layerTreeView = 0; | |
| 89 } | |
| 90 | |
| 91 void WebPopupMenuImpl::initialize(PopupContainer* widget, const WebRect& bounds) | |
| 92 { | |
| 93 m_widget = widget; | |
| 94 m_widget->setClient(this); | |
| 95 | |
| 96 if (!m_client) | |
| 97 return; | |
| 98 m_client->setWindowRect(bounds); | |
| 99 m_client->show(WebNavigationPolicy()); // Policy is ignored. | |
| 100 | |
| 101 m_client->initializeLayerTreeView(); | |
| 102 m_layerTreeView = m_client->layerTreeView(); | |
| 103 if (m_layerTreeView) { | |
| 104 m_layerTreeView->setVisible(true); | |
| 105 m_layerTreeView->setDeviceScaleFactor(m_client->deviceScaleFactor()); | |
| 106 m_rootLayer = adoptPtr(Platform::current()->compositorSupport()->createC
ontentLayer(this)); | |
| 107 m_rootLayer->layer()->setBounds(m_size); | |
| 108 // FIXME: Legacy LCD behavior (http://crbug.com/436821), but are we alwa
ys guaranteed to be opaque? | |
| 109 m_rootLayer->layer()->setOpaque(true); | |
| 110 m_layerTreeView->setRootLayer(*m_rootLayer->layer()); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 void WebPopupMenuImpl::handleMouseMove(const WebMouseEvent& event) | |
| 115 { | |
| 116 // Don't send mouse move messages if the mouse hasn't moved. | |
| 117 if (event.x != m_lastMousePosition.x || event.y != m_lastMousePosition.y) { | |
| 118 m_lastMousePosition = WebPoint(event.x, event.y); | |
| 119 m_widget->handleMouseMoveEvent(PlatformMouseEventBuilder(m_widget, event
)); | |
| 120 | |
| 121 // We cannot call setToolTipText() in PopupContainer, because PopupConta
iner is in WebCore, and we cannot refer to WebKit from Webcore. | |
| 122 PopupContainer* container = static_cast<PopupContainer*>(m_widget); | |
| 123 client()->setToolTipText(container->getSelectedItemToolTip(), toWebTextD
irection(container->menuStyle().textDirection())); | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 void WebPopupMenuImpl::handleMouseLeave(const WebMouseEvent& event) | |
| 128 { | |
| 129 m_widget->handleMouseMoveEvent(PlatformMouseEventBuilder(m_widget, event)); | |
| 130 } | |
| 131 | |
| 132 void WebPopupMenuImpl::handleMouseDown(const WebMouseEvent& event) | |
| 133 { | |
| 134 m_widget->handleMouseDownEvent(PlatformMouseEventBuilder(m_widget, event)); | |
| 135 } | |
| 136 | |
| 137 void WebPopupMenuImpl::handleMouseUp(const WebMouseEvent& event) | |
| 138 { | |
| 139 mouseCaptureLost(); | |
| 140 m_widget->handleMouseReleaseEvent(PlatformMouseEventBuilder(m_widget, event)
); | |
| 141 } | |
| 142 | |
| 143 void WebPopupMenuImpl::handleMouseWheel(const WebMouseWheelEvent& event) | |
| 144 { | |
| 145 m_widget->handleWheelEvent(PlatformWheelEventBuilder(m_widget, event)); | |
| 146 } | |
| 147 | |
| 148 bool WebPopupMenuImpl::handleGestureEvent(const WebGestureEvent& event) | |
| 149 { | |
| 150 return m_widget->handleGestureEvent(PlatformGestureEventBuilder(m_widget, ev
ent)); | |
| 151 } | |
| 152 | |
| 153 bool WebPopupMenuImpl::handleTouchEvent(const WebTouchEvent& event) | |
| 154 { | |
| 155 | |
| 156 PlatformTouchEventBuilder touchEventBuilder(m_widget, event); | |
| 157 bool defaultPrevented(m_widget->handleTouchEvent(touchEventBuilder)); | |
| 158 return defaultPrevented; | |
| 159 } | |
| 160 | |
| 161 bool WebPopupMenuImpl::handleKeyEvent(const WebKeyboardEvent& event) | |
| 162 { | |
| 163 return m_widget->handleKeyEvent(PlatformKeyboardEventBuilder(event)); | |
| 164 } | |
| 165 | |
| 166 // WebWidget ------------------------------------------------------------------- | |
| 167 | |
| 168 void WebPopupMenuImpl::close() | |
| 169 { | |
| 170 if (m_widget) | |
| 171 m_widget->hide(); | |
| 172 | |
| 173 m_client = 0; | |
| 174 | |
| 175 deref(); // Balances ref() from WebPopupMenu::create. | |
| 176 } | |
| 177 | |
| 178 void WebPopupMenuImpl::willStartLiveResize() | |
| 179 { | |
| 180 } | |
| 181 | |
| 182 void WebPopupMenuImpl::resize(const WebSize& newSize) | |
| 183 { | |
| 184 if (m_size == newSize) | |
| 185 return; | |
| 186 m_size = newSize; | |
| 187 | |
| 188 if (m_widget) { | |
| 189 IntRect newGeometry(0, 0, m_size.width, m_size.height); | |
| 190 m_widget->setFrameRect(newGeometry); | |
| 191 } | |
| 192 | |
| 193 if (m_client) { | |
| 194 WebRect damagedRect(0, 0, m_size.width, m_size.height); | |
| 195 m_client->didInvalidateRect(damagedRect); | |
| 196 } | |
| 197 | |
| 198 if (m_rootLayer) | |
| 199 m_rootLayer->layer()->setBounds(newSize); | |
| 200 } | |
| 201 | |
| 202 void WebPopupMenuImpl::willEndLiveResize() | |
| 203 { | |
| 204 } | |
| 205 | |
| 206 void WebPopupMenuImpl::beginFrame(const WebBeginFrameArgs&) | |
| 207 { | |
| 208 } | |
| 209 | |
| 210 void WebPopupMenuImpl::layout() | |
| 211 { | |
| 212 } | |
| 213 | |
| 214 void WebPopupMenuImpl::paintContents(WebCanvas* canvas, const WebRect& rect, boo
l, WebContentLayerClient::GraphicsContextStatus contextStatus) | |
| 215 { | |
| 216 if (!m_widget) | |
| 217 return; | |
| 218 | |
| 219 if (!rect.isEmpty()) { | |
| 220 GraphicsContext context(canvas, nullptr, | |
| 221 contextStatus == WebContentLayerClient::GraphicsContextEnabled ? Gra
phicsContext::NothingDisabled : GraphicsContext::FullyDisabled); | |
| 222 m_widget->paint(&context, rect); | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 void WebPopupMenuImpl::paint(WebCanvas* canvas, const WebRect& rect) | |
| 227 { | |
| 228 if (!m_widget) | |
| 229 return; | |
| 230 | |
| 231 if (!rect.isEmpty()) { | |
| 232 GraphicsContext context(canvas, nullptr); | |
| 233 float scaleFactor = m_client->deviceScaleFactor(); | |
| 234 context.scale(scaleFactor, scaleFactor); | |
| 235 m_widget->paint(&context, rect); | |
| 236 } | |
| 237 } | |
| 238 | |
| 239 void WebPopupMenuImpl::themeChanged() | |
| 240 { | |
| 241 notImplemented(); | |
| 242 } | |
| 243 | |
| 244 bool WebPopupMenuImpl::handleInputEvent(const WebInputEvent& inputEvent) | |
| 245 { | |
| 246 if (!m_widget) | |
| 247 return false; | |
| 248 | |
| 249 // FIXME: WebKit seems to always return false on mouse events methods. For | |
| 250 // now we'll assume it has processed them (as we are only interested in | |
| 251 // whether keyboard events are processed). | |
| 252 switch (inputEvent.type) { | |
| 253 case WebInputEvent::MouseMove: | |
| 254 handleMouseMove(static_cast<const WebMouseEvent&>(inputEvent)); | |
| 255 return true; | |
| 256 | |
| 257 case WebInputEvent::MouseLeave: | |
| 258 handleMouseLeave(static_cast<const WebMouseEvent&>(inputEvent)); | |
| 259 return true; | |
| 260 | |
| 261 case WebInputEvent::MouseWheel: | |
| 262 handleMouseWheel(static_cast<const WebMouseWheelEvent&>(inputEvent)); | |
| 263 return true; | |
| 264 | |
| 265 case WebInputEvent::MouseDown: | |
| 266 handleMouseDown(static_cast<const WebMouseEvent&>(inputEvent)); | |
| 267 return true; | |
| 268 | |
| 269 case WebInputEvent::MouseUp: | |
| 270 handleMouseUp(static_cast<const WebMouseEvent&>(inputEvent)); | |
| 271 return true; | |
| 272 | |
| 273 // In Windows, RawKeyDown only has information about the physical key, but | |
| 274 // for "selection", we need the information about the character the key | |
| 275 // translated into. For English, the physical key value and the character | |
| 276 // value are the same, hence, "selection" works for English. But for other | |
| 277 // languages, such as Hebrew, the character value is different from the | |
| 278 // physical key value. Thus, without accepting Char event type which | |
| 279 // contains the key's character value, the "selection" won't work for | |
| 280 // non-English languages, such as Hebrew. | |
| 281 case WebInputEvent::RawKeyDown: | |
| 282 case WebInputEvent::KeyDown: | |
| 283 case WebInputEvent::KeyUp: | |
| 284 case WebInputEvent::Char: | |
| 285 return handleKeyEvent(static_cast<const WebKeyboardEvent&>(inputEvent)); | |
| 286 | |
| 287 case WebInputEvent::TouchStart: | |
| 288 case WebInputEvent::TouchMove: | |
| 289 case WebInputEvent::TouchEnd: | |
| 290 case WebInputEvent::TouchCancel: | |
| 291 return handleTouchEvent(static_cast<const WebTouchEvent&>(inputEvent)); | |
| 292 | |
| 293 case WebInputEvent::GestureScrollBegin: | |
| 294 case WebInputEvent::GestureScrollEnd: | |
| 295 case WebInputEvent::GestureScrollUpdate: | |
| 296 case WebInputEvent::GestureFlingStart: | |
| 297 case WebInputEvent::GestureFlingCancel: | |
| 298 case WebInputEvent::GestureTap: | |
| 299 case WebInputEvent::GestureTapUnconfirmed: | |
| 300 case WebInputEvent::GestureTapDown: | |
| 301 case WebInputEvent::GestureShowPress: | |
| 302 case WebInputEvent::GestureTapCancel: | |
| 303 case WebInputEvent::GestureDoubleTap: | |
| 304 case WebInputEvent::GestureTwoFingerTap: | |
| 305 case WebInputEvent::GestureLongPress: | |
| 306 case WebInputEvent::GestureLongTap: | |
| 307 case WebInputEvent::GesturePinchBegin: | |
| 308 case WebInputEvent::GesturePinchEnd: | |
| 309 case WebInputEvent::GesturePinchUpdate: | |
| 310 return handleGestureEvent(static_cast<const WebGestureEvent&>(inputEvent
)); | |
| 311 | |
| 312 case WebInputEvent::Undefined: | |
| 313 case WebInputEvent::MouseEnter: | |
| 314 case WebInputEvent::ContextMenu: | |
| 315 return false; | |
| 316 } | |
| 317 return false; | |
| 318 } | |
| 319 | |
| 320 void WebPopupMenuImpl::mouseCaptureLost() | |
| 321 { | |
| 322 } | |
| 323 | |
| 324 void WebPopupMenuImpl::setFocus(bool) | |
| 325 { | |
| 326 } | |
| 327 | |
| 328 bool WebPopupMenuImpl::setComposition(const WebString&, const WebVector<WebCompo
sitionUnderline>&, int, int) | |
| 329 { | |
| 330 return false; | |
| 331 } | |
| 332 | |
| 333 bool WebPopupMenuImpl::confirmComposition() | |
| 334 { | |
| 335 return false; | |
| 336 } | |
| 337 | |
| 338 bool WebPopupMenuImpl::confirmComposition(ConfirmCompositionBehavior) | |
| 339 { | |
| 340 return false; | |
| 341 } | |
| 342 | |
| 343 bool WebPopupMenuImpl::confirmComposition(const WebString&) | |
| 344 { | |
| 345 return false; | |
| 346 } | |
| 347 | |
| 348 bool WebPopupMenuImpl::compositionRange(size_t* location, size_t* length) | |
| 349 { | |
| 350 *location = 0; | |
| 351 *length = 0; | |
| 352 return false; | |
| 353 } | |
| 354 | |
| 355 bool WebPopupMenuImpl::caretOrSelectionRange(size_t* location, size_t* length) | |
| 356 { | |
| 357 *location = 0; | |
| 358 *length = 0; | |
| 359 return false; | |
| 360 } | |
| 361 | |
| 362 void WebPopupMenuImpl::setTextDirection(WebTextDirection) | |
| 363 { | |
| 364 } | |
| 365 | |
| 366 | |
| 367 //----------------------------------------------------------------------------- | |
| 368 // HostWindow | |
| 369 | |
| 370 void WebPopupMenuImpl::invalidateContentsAndRootView(const IntRect& paintRect) | |
| 371 { | |
| 372 if (paintRect.isEmpty()) | |
| 373 return; | |
| 374 if (m_client) | |
| 375 m_client->didInvalidateRect(paintRect); | |
| 376 if (m_rootLayer) | |
| 377 m_rootLayer->layer()->invalidateRect(paintRect); | |
| 378 } | |
| 379 | |
| 380 void WebPopupMenuImpl::invalidateContentsForSlowScroll(const IntRect& updateRect
) | |
| 381 { | |
| 382 invalidateContentsAndRootView(updateRect); | |
| 383 } | |
| 384 | |
| 385 void WebPopupMenuImpl::scheduleAnimation() | |
| 386 { | |
| 387 } | |
| 388 | |
| 389 IntRect WebPopupMenuImpl::rootViewToScreen(const IntRect& rect) const | |
| 390 { | |
| 391 notImplemented(); | |
| 392 return IntRect(); | |
| 393 } | |
| 394 | |
| 395 WebScreenInfo WebPopupMenuImpl::screenInfo() const | |
| 396 { | |
| 397 return WebScreenInfo(); | |
| 398 } | |
| 399 | |
| 400 void WebPopupMenuImpl::popupClosed(PopupContainer* widget) | |
| 401 { | |
| 402 ASSERT(widget == m_widget); | |
| 403 if (m_widget) { | |
| 404 m_widget->setClient(0); | |
| 405 m_widget = 0; | |
| 406 } | |
| 407 if (m_client) | |
| 408 m_client->closeWidgetSoon(); | |
| 409 } | |
| 410 | |
| 411 } // namespace blink | |
| OLD | NEW |