Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: Source/web/WebPopupMenuImpl.cpp

Issue 1142303005: Remove legacy SELECT popup code. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/web/WebPopupMenuImpl.h ('k') | Source/web/WebViewImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "core/paint/TransformRecorder.h"
36 #include "platform/Cursor.h"
37 #include "platform/NotImplemented.h"
38 #include "platform/PlatformGestureEvent.h"
39 #include "platform/PlatformKeyboardEvent.h"
40 #include "platform/PlatformMouseEvent.h"
41 #include "platform/PlatformWheelEvent.h"
42 #include "platform/RuntimeEnabledFeatures.h"
43 #include "platform/geometry/IntRect.h"
44 #include "platform/graphics/GraphicsContext.h"
45 #include "platform/graphics/paint/DisplayItemList.h"
46 #include "platform/graphics/paint/SkPictureBuilder.h"
47 #include "platform/graphics/skia/SkiaUtils.h"
48 #include "public/platform/Platform.h"
49 #include "public/platform/WebCompositorSupport.h"
50 #include "public/platform/WebContentLayer.h"
51 #include "public/platform/WebFloatRect.h"
52 #include "public/platform/WebLayerTreeView.h"
53 #include "public/platform/WebRect.h"
54 #include "public/web/WebInputEvent.h"
55 #include "public/web/WebRange.h"
56 #include "public/web/WebViewClient.h"
57 #include "public/web/WebWidgetClient.h"
58 #include "web/PopupContainer.h"
59 #include "web/PopupMenuChromium.h"
60 #include "web/WebInputEventConversion.h"
61
62 namespace blink {
63
64 // WebPopupMenu ---------------------------------------------------------------
65
66 WebPopupMenu* WebPopupMenu::create(WebWidgetClient* client)
67 {
68 // Pass the WebPopupMenuImpl's self-reference to the caller.
69 return adoptRef(new WebPopupMenuImpl(client)).leakRef();
70 }
71
72 // WebWidget ------------------------------------------------------------------
73
74 WebPopupMenuImpl::WebPopupMenuImpl(WebWidgetClient* client)
75 : m_client(client)
76 , m_layerTreeView(0)
77 // Set to impossible point so we always get the first mouse position.
78 , m_lastMousePosition(WebPoint(-1, -1))
79 , m_widget(0)
80 {
81 if (RuntimeEnabledFeatures::slimmingPaintEnabled())
82 m_displayItemList = DisplayItemList::create();
83 }
84
85 WebPopupMenuImpl::~WebPopupMenuImpl()
86 {
87 if (m_widget)
88 m_widget->setClient(0);
89 }
90
91 void WebPopupMenuImpl::willCloseLayerTreeView()
92 {
93 m_layerTreeView = 0;
94 }
95
96 void WebPopupMenuImpl::initialize(PopupContainer* widget, const WebRect& bounds)
97 {
98 m_widget = widget;
99 m_widget->setClient(this);
100
101 if (!m_client)
102 return;
103 m_client->setWindowRect(bounds);
104 m_client->show(WebNavigationPolicy()); // Policy is ignored.
105
106 m_client->initializeLayerTreeView();
107 m_layerTreeView = m_client->layerTreeView();
108 if (m_layerTreeView) {
109 m_layerTreeView->setVisible(true);
110 m_layerTreeView->setDeviceScaleFactor(m_client->deviceScaleFactor());
111 m_rootLayer = adoptPtr(Platform::current()->compositorSupport()->createC ontentLayer(this));
112 m_rootLayer->layer()->setBounds(m_size);
113 // FIXME: Legacy LCD behavior (http://crbug.com/436821), but are we alwa ys guaranteed to be opaque?
114 m_rootLayer->layer()->setOpaque(true);
115 m_layerTreeView->setRootLayer(*m_rootLayer->layer());
116 }
117 }
118
119 void WebPopupMenuImpl::handleMouseMove(const WebMouseEvent& event)
120 {
121 // Don't send mouse move messages if the mouse hasn't moved.
122 if (event.x != m_lastMousePosition.x || event.y != m_lastMousePosition.y) {
123 m_lastMousePosition = WebPoint(event.x, event.y);
124 m_widget->handleMouseMoveEvent(PlatformMouseEventBuilder(m_widget, event ));
125
126 // We cannot call setToolTipText() in PopupContainer, because PopupConta iner is in WebCore, and we cannot refer to WebKit from Webcore.
127 PopupContainer* container = static_cast<PopupContainer*>(m_widget);
128 client()->setToolTipText(container->getSelectedItemToolTip(), toWebTextD irection(container->menuStyle().textDirection()));
129 }
130 }
131
132 void WebPopupMenuImpl::handleMouseLeave(const WebMouseEvent& event)
133 {
134 m_widget->handleMouseMoveEvent(PlatformMouseEventBuilder(m_widget, event));
135 }
136
137 void WebPopupMenuImpl::handleMouseDown(const WebMouseEvent& event)
138 {
139 m_widget->handleMouseDownEvent(PlatformMouseEventBuilder(m_widget, event));
140 }
141
142 void WebPopupMenuImpl::handleMouseUp(const WebMouseEvent& event)
143 {
144 mouseCaptureLost();
145 m_widget->handleMouseReleaseEvent(PlatformMouseEventBuilder(m_widget, event) );
146 }
147
148 void WebPopupMenuImpl::handleMouseWheel(const WebMouseWheelEvent& event)
149 {
150 m_widget->handleWheelEvent(PlatformWheelEventBuilder(m_widget, event));
151 }
152
153 bool WebPopupMenuImpl::handleGestureEvent(const WebGestureEvent& event)
154 {
155 return m_widget->handleGestureEvent(PlatformGestureEventBuilder(m_widget, ev ent));
156 }
157
158 bool WebPopupMenuImpl::handleTouchEvent(const WebTouchEvent& event)
159 {
160
161 PlatformTouchEventBuilder touchEventBuilder(m_widget, event);
162 bool defaultPrevented(m_widget->handleTouchEvent(touchEventBuilder));
163 return defaultPrevented;
164 }
165
166 bool WebPopupMenuImpl::handleKeyEvent(const WebKeyboardEvent& event)
167 {
168 return m_widget->handleKeyEvent(PlatformKeyboardEventBuilder(event));
169 }
170
171 // WebWidget -------------------------------------------------------------------
172
173 void WebPopupMenuImpl::close()
174 {
175 if (m_widget)
176 m_widget->hide();
177
178 m_client = 0;
179
180 deref(); // Balances ref() from WebPopupMenu::create.
181 }
182
183 void WebPopupMenuImpl::willStartLiveResize()
184 {
185 }
186
187 void WebPopupMenuImpl::resize(const WebSize& newSize)
188 {
189 if (m_size == newSize)
190 return;
191 m_size = newSize;
192
193 if (m_widget) {
194 IntRect newGeometry(0, 0, m_size.width, m_size.height);
195 m_widget->setFrameRect(newGeometry);
196 }
197
198 if (m_client) {
199 WebRect damagedRect(0, 0, m_size.width, m_size.height);
200 m_client->didInvalidateRect(damagedRect);
201 }
202
203 if (m_rootLayer)
204 m_rootLayer->layer()->setBounds(newSize);
205 }
206
207 void WebPopupMenuImpl::willEndLiveResize()
208 {
209 }
210
211 void WebPopupMenuImpl::beginFrame(const WebBeginFrameArgs&)
212 {
213 }
214
215 void WebPopupMenuImpl::layout()
216 {
217 }
218
219 void WebPopupMenuImpl::paintContents(WebCanvas* canvas, const WebRect& rect, Web ContentLayerClient::PaintingControlSetting paintingControl)
220 {
221 if (!m_widget)
222 return;
223
224 OwnPtr<GraphicsContext> context;
225 GraphicsContext::DisabledMode disabledMode = GraphicsContext::NothingDisable d;
226 if (paintingControl == PaintingControlSetting::DisplayListPaintingDisabled
227 || paintingControl == PaintingControlSetting::DisplayListConstructionDis abled)
228 disabledMode = GraphicsContext::FullyDisabled;
229
230 IntRect intRect(rect);
231 SkPictureBuilder builder(intRect, disabledMode);
232
233 m_widget->paint(&builder.context(), rect);
234 builder.endRecording()->playback(canvas);
235 }
236
237 void WebPopupMenuImpl::paintContents(WebDisplayItemList* webDisplayItemList, con st WebRect& rect, WebContentLayerClient::PaintingControlSetting paintingControl)
238 {
239 if (!m_widget)
240 return;
241
242 RELEASE_ASSERT(m_displayItemList);
243
244 GraphicsContext::DisabledMode disabledMode = GraphicsContext::NothingDisable d;
245 if (paintingControl == PaintingControlSetting::DisplayListPaintingDisabled
246 || paintingControl == PaintingControlSetting::DisplayListConstructionDis abled)
247 disabledMode = GraphicsContext::FullyDisabled;
248
249 GraphicsContext context(m_displayItemList.get(), disabledMode);
250 m_displayItemList->setDisplayItemConstructionIsDisabled(paintingControl == P aintingControlSetting::DisplayListConstructionDisabled);
251 m_widget->paint(&context, rect);
252
253 m_displayItemList->commitNewDisplayItems();
254
255 for (const auto& item : m_displayItemList->displayItems())
256 item->appendToWebDisplayItemList(webDisplayItemList);
257 }
258
259 void WebPopupMenuImpl::paint(WebCanvas* canvas, const WebRect& rect)
260 {
261 if (!m_widget)
262 return;
263
264 if (!rect.isEmpty()) {
265 IntRect intRect(rect);
266 SkPictureBuilder pictureBuilder(intRect);
267
268 AffineTransform transform;
269 transform.scale(m_client->deviceScaleFactor());
270 TransformRecorder transformRecorder(pictureBuilder.context(), *this, tra nsform);
271
272 m_widget->paint(&pictureBuilder.context(), rect);
273
274 pictureBuilder.endRecording()->playback(canvas);
275 }
276 }
277
278 void WebPopupMenuImpl::themeChanged()
279 {
280 notImplemented();
281 }
282
283 bool WebPopupMenuImpl::handleInputEvent(const WebInputEvent& inputEvent)
284 {
285 if (!m_widget)
286 return false;
287
288 // FIXME: WebKit seems to always return false on mouse events methods. For
289 // now we'll assume it has processed them (as we are only interested in
290 // whether keyboard events are processed).
291 switch (inputEvent.type) {
292 case WebInputEvent::MouseMove:
293 handleMouseMove(static_cast<const WebMouseEvent&>(inputEvent));
294 return true;
295
296 case WebInputEvent::MouseLeave:
297 handleMouseLeave(static_cast<const WebMouseEvent&>(inputEvent));
298 return true;
299
300 case WebInputEvent::MouseWheel:
301 handleMouseWheel(static_cast<const WebMouseWheelEvent&>(inputEvent));
302 return true;
303
304 case WebInputEvent::MouseDown:
305 handleMouseDown(static_cast<const WebMouseEvent&>(inputEvent));
306 return true;
307
308 case WebInputEvent::MouseUp:
309 handleMouseUp(static_cast<const WebMouseEvent&>(inputEvent));
310 return true;
311
312 // In Windows, RawKeyDown only has information about the physical key, but
313 // for "selection", we need the information about the character the key
314 // translated into. For English, the physical key value and the character
315 // value are the same, hence, "selection" works for English. But for other
316 // languages, such as Hebrew, the character value is different from the
317 // physical key value. Thus, without accepting Char event type which
318 // contains the key's character value, the "selection" won't work for
319 // non-English languages, such as Hebrew.
320 case WebInputEvent::RawKeyDown:
321 case WebInputEvent::KeyDown:
322 case WebInputEvent::KeyUp:
323 case WebInputEvent::Char:
324 return handleKeyEvent(static_cast<const WebKeyboardEvent&>(inputEvent));
325
326 case WebInputEvent::TouchStart:
327 case WebInputEvent::TouchMove:
328 case WebInputEvent::TouchEnd:
329 case WebInputEvent::TouchCancel:
330 return handleTouchEvent(static_cast<const WebTouchEvent&>(inputEvent));
331
332 case WebInputEvent::GestureScrollBegin:
333 case WebInputEvent::GestureScrollEnd:
334 case WebInputEvent::GestureScrollUpdate:
335 case WebInputEvent::GestureFlingStart:
336 case WebInputEvent::GestureFlingCancel:
337 case WebInputEvent::GestureTap:
338 case WebInputEvent::GestureTapUnconfirmed:
339 case WebInputEvent::GestureTapDown:
340 case WebInputEvent::GestureShowPress:
341 case WebInputEvent::GestureTapCancel:
342 case WebInputEvent::GestureDoubleTap:
343 case WebInputEvent::GestureTwoFingerTap:
344 case WebInputEvent::GestureLongPress:
345 case WebInputEvent::GestureLongTap:
346 case WebInputEvent::GesturePinchBegin:
347 case WebInputEvent::GesturePinchEnd:
348 case WebInputEvent::GesturePinchUpdate:
349 return handleGestureEvent(static_cast<const WebGestureEvent&>(inputEvent ));
350
351 case WebInputEvent::Undefined:
352 case WebInputEvent::MouseEnter:
353 case WebInputEvent::ContextMenu:
354 return false;
355 }
356 return false;
357 }
358
359 void WebPopupMenuImpl::mouseCaptureLost()
360 {
361 }
362
363 void WebPopupMenuImpl::setFocus(bool)
364 {
365 }
366
367 bool WebPopupMenuImpl::setComposition(const WebString&, const WebVector<WebCompo sitionUnderline>&, int, int)
368 {
369 return false;
370 }
371
372 bool WebPopupMenuImpl::confirmComposition()
373 {
374 return false;
375 }
376
377 bool WebPopupMenuImpl::confirmComposition(ConfirmCompositionBehavior)
378 {
379 return false;
380 }
381
382 bool WebPopupMenuImpl::confirmComposition(const WebString&)
383 {
384 return false;
385 }
386
387 bool WebPopupMenuImpl::compositionRange(size_t* location, size_t* length)
388 {
389 *location = 0;
390 *length = 0;
391 return false;
392 }
393
394 bool WebPopupMenuImpl::caretOrSelectionRange(size_t* location, size_t* length)
395 {
396 *location = 0;
397 *length = 0;
398 return false;
399 }
400
401 void WebPopupMenuImpl::setTextDirection(WebTextDirection)
402 {
403 }
404
405
406 //-----------------------------------------------------------------------------
407 // HostWindow
408
409 void WebPopupMenuImpl::invalidateRect(const IntRect& paintRect)
410 {
411 if (paintRect.isEmpty())
412 return;
413 if (m_client)
414 m_client->didInvalidateRect(paintRect);
415 if (m_rootLayer)
416 m_rootLayer->layer()->invalidateRect(paintRect);
417 }
418
419 void WebPopupMenuImpl::scheduleAnimation()
420 {
421 }
422
423 IntRect WebPopupMenuImpl::viewportToScreen(const IntRect& rect) const
424 {
425 notImplemented();
426 return IntRect();
427 }
428
429 void WebPopupMenuImpl::popupClosed(PopupContainer* widget)
430 {
431 ASSERT(widget == m_widget);
432 if (m_widget) {
433 m_widget->setClient(0);
434 m_widget = 0;
435 }
436 if (m_client)
437 m_client->closeWidgetSoon();
438 }
439
440 void WebPopupMenuImpl::invalidateDisplayItemClient(DisplayItemClient client)
441 {
442 if (m_displayItemList) {
443 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled());
444 m_displayItemList->invalidate(client);
445 }
446 }
447
448 void WebPopupMenuImpl::invalidateAllDisplayItems()
449 {
450 if (m_displayItemList) {
451 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled());
452 m_displayItemList->invalidateAll();
453 }
454 }
455
456 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebPopupMenuImpl.h ('k') | Source/web/WebViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698