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

Side by Side Diff: webkit/api/src/WebPopupMenuImpl.cpp

Issue 338041: Move a bunch of files into webkit/api/src... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 /*
2 // Use of this source code is governed by a BSD-style license that can be 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 // found in the LICENSE file. 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 */
4 30
5 #include "config.h" 31 #include "config.h"
32 #include "WebPopupMenuImpl.h"
33
34 #include <skia/ext/platform_canvas.h>
6 35
7 #include "Cursor.h" 36 #include "Cursor.h"
8 #include "FramelessScrollView.h" 37 #include "FramelessScrollView.h"
9 #include "FrameView.h" 38 #include "FrameView.h"
10 #include "IntRect.h" 39 #include "IntRect.h"
11 #include "PlatformContextSkia.h" 40 #include "PlatformContextSkia.h"
12 #include "PlatformKeyboardEvent.h" 41 #include "PlatformKeyboardEvent.h"
13 #include "PlatformMouseEvent.h" 42 #include "PlatformMouseEvent.h"
14 #include "PlatformWheelEvent.h" 43 #include "PlatformWheelEvent.h"
15 #include "SkiaUtils.h" 44 #include "SkiaUtils.h"
16 #undef LOG 45 #include "WebInputEvent.h"
17 46 #include "WebRect.h"
18 #include "skia/ext/platform_canvas.h" 47 #include "WebWidgetClient.h"
19 #include "webkit/api/public/WebInputEvent.h" 48 #include "WebInputEventConversion.h"
20 #include "webkit/api/public/WebRect.h"
21 #include "webkit/api/public/WebWidgetClient.h"
22 #include "webkit/api/src/WebInputEventConversion.h"
23 #include "webkit/glue/glue_util.h"
24 #include "webkit/glue/webpopupmenu_impl.h"
25 49
26 using namespace WebCore; 50 using namespace WebCore;
27 51
28 using WebKit::PlatformKeyboardEventBuilder; 52 namespace WebKit {
29 using WebKit::PlatformMouseEventBuilder;
30 using WebKit::PlatformWheelEventBuilder;
31 using WebKit::WebCanvas;
32 using WebKit::WebCompositionCommand;
33 using WebKit::WebInputEvent;
34 using WebKit::WebKeyboardEvent;
35 using WebKit::WebMouseEvent;
36 using WebKit::WebMouseWheelEvent;
37 using WebKit::WebNavigationPolicy;
38 using WebKit::WebPoint;
39 using WebKit::WebPopupMenu;
40 using WebKit::WebRect;
41 using WebKit::WebSize;
42 using WebKit::WebString;
43 using WebKit::WebTextDirection;
44 using WebKit::WebWidget;
45 using WebKit::WebWidgetClient;
46 53
47 // WebPopupMenu --------------------------------------------------------------- 54 // WebPopupMenu ---------------------------------------------------------------
48 55
49 // static 56 WebPopupMenu* WebPopupMenu::create(WebWidgetClient* client)
50 WebPopupMenu* WebPopupMenu::create(WebWidgetClient* client) { 57 {
51 return new WebPopupMenuImpl(client); 58 return new WebPopupMenuImpl(client);
52 } 59 }
53 60
54 // WebWidget ------------------------------------------------------------------ 61 // WebWidget ------------------------------------------------------------------
55 62
56 WebPopupMenuImpl::WebPopupMenuImpl(WebWidgetClient* client) 63 WebPopupMenuImpl::WebPopupMenuImpl(WebWidgetClient* client)
57 : client_(client), 64 : m_client(client)
58 widget_(NULL) { 65 , m_widget(0)
59 // set to impossible point so we always get the first mouse pos 66 {
60 last_mouse_position_ = WebPoint(-1, -1); 67 // set to impossible point so we always get the first mouse pos
68 m_lastMousePosition = WebPoint(-1, -1);
61 } 69 }
62 70
63 WebPopupMenuImpl::~WebPopupMenuImpl() { 71 WebPopupMenuImpl::~WebPopupMenuImpl()
64 if (widget_) 72 {
65 widget_->setClient(NULL); 73 if (m_widget)
74 m_widget->setClient(0);
66 } 75 }
67 76
68 void WebPopupMenuImpl::Init(WebCore::FramelessScrollView* widget, 77 void WebPopupMenuImpl::Init(FramelessScrollView* widget, const WebRect& bounds)
69 const WebRect& bounds) { 78 {
70 widget_ = widget; 79 m_widget = widget;
71 widget_->setClient(this); 80 m_widget->setClient(this);
72 81
73 if (client_) { 82 if (m_client) {
74 client_->setWindowRect(bounds); 83 m_client->setWindowRect(bounds);
75 client_->show(WebNavigationPolicy()); // Policy is ignored 84 m_client->show(WebNavigationPolicy()); // Policy is ignored
76 } 85 }
77 } 86 }
78 87
79 void WebPopupMenuImpl::MouseMove(const WebMouseEvent& event) { 88 void WebPopupMenuImpl::MouseMove(const WebMouseEvent& event)
80 // don't send mouse move messages if the mouse hasn't moved. 89 {
81 if (event.x != last_mouse_position_.x || 90 // don't send mouse move messages if the mouse hasn't moved.
82 event.y != last_mouse_position_.y) { 91 if (event.x != m_lastMousePosition.x || event.y != m_lastMousePosition.y) {
83 last_mouse_position_ = WebPoint(event.x, event.y); 92 m_lastMousePosition = WebPoint(event.x, event.y);
84 widget_->handleMouseMoveEvent(PlatformMouseEventBuilder(widget_, event)); 93 m_widget->handleMouseMoveEvent(PlatformMouseEventBuilder(m_widget, event));
85 } 94 }
86 } 95 }
87 96
88 void WebPopupMenuImpl::MouseLeave(const WebMouseEvent& event) { 97 void WebPopupMenuImpl::MouseLeave(const WebMouseEvent& event)
89 widget_->handleMouseMoveEvent(PlatformMouseEventBuilder(widget_, event)); 98 {
99 m_widget->handleMouseMoveEvent(PlatformMouseEventBuilder(m_widget, event));
90 } 100 }
91 101
92 void WebPopupMenuImpl::MouseDown(const WebMouseEvent& event) { 102 void WebPopupMenuImpl::MouseDown(const WebMouseEvent& event)
93 widget_->handleMouseDownEvent(PlatformMouseEventBuilder(widget_, event)); 103 {
104 m_widget->handleMouseDownEvent(PlatformMouseEventBuilder(m_widget, event));
94 } 105 }
95 106
96 void WebPopupMenuImpl::MouseUp(const WebMouseEvent& event) { 107 void WebPopupMenuImpl::MouseUp(const WebMouseEvent& event)
97 mouseCaptureLost(); 108 {
98 widget_->handleMouseReleaseEvent(PlatformMouseEventBuilder(widget_, event)); 109 mouseCaptureLost();
110 m_widget->handleMouseReleaseEvent(PlatformMouseEventBuilder(m_widget, event));
99 } 111 }
100 112
101 void WebPopupMenuImpl::MouseWheel(const WebMouseWheelEvent& event) { 113 void WebPopupMenuImpl::MouseWheel(const WebMouseWheelEvent& event)
102 widget_->handleWheelEvent(PlatformWheelEventBuilder(widget_, event)); 114 {
115 m_widget->handleWheelEvent(PlatformWheelEventBuilder(m_widget, event));
103 } 116 }
104 117
105 bool WebPopupMenuImpl::KeyEvent(const WebKeyboardEvent& event) { 118 bool WebPopupMenuImpl::KeyEvent(const WebKeyboardEvent& event)
106 return widget_->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 119 {
120 return m_widget->handleKeyEvent(PlatformKeyboardEventBuilder(event));
107 } 121 }
108 122
109 // WebWidget ------------------------------------------------------------------- 123 // WebWidget -------------------------------------------------------------------
110 124
111 void WebPopupMenuImpl::close() { 125 void WebPopupMenuImpl::close()
112 if (widget_) 126 {
113 widget_->hide(); 127 if (m_widget)
128 m_widget->hide();
114 129
115 client_ = NULL; 130 m_client = 0;
116 131
117 deref(); // Balances ref() from WebWidget::Create 132 deref(); // Balances ref() from WebWidget::Create
118 } 133 }
119 134
120 void WebPopupMenuImpl::resize(const WebSize& new_size) { 135 void WebPopupMenuImpl::resize(const WebSize& newSize)
121 if (size_ == new_size) 136 {
122 return; 137 if (m_size == newSize)
123 size_ = new_size; 138 return;
139 m_size = newSize;
124 140
125 if (widget_) { 141 if (m_widget) {
126 IntRect new_geometry(0, 0, size_.width, size_.height); 142 IntRect newGeometry(0, 0, m_size.width, m_size.height);
127 widget_->setFrameRect(new_geometry); 143 m_widget->setFrameRect(newGeometry);
128 } 144 }
129 145
130 if (client_) { 146 if (m_client) {
131 WebRect damaged_rect(0, 0, size_.width, size_.height); 147 WebRect damagedRect(0, 0, m_size.width, m_size.height);
132 client_->didInvalidateRect(damaged_rect); 148 m_client->didInvalidateRect(damagedRect);
133 } 149 }
134 } 150 }
135 151
136 void WebPopupMenuImpl::layout() { 152 void WebPopupMenuImpl::layout()
153 {
137 } 154 }
138 155
139 void WebPopupMenuImpl::paint(WebCanvas* canvas, const WebRect& rect) { 156 void WebPopupMenuImpl::paint(WebCanvas* canvas, const WebRect& rect)
140 if (!widget_) 157 {
141 return; 158 if (!m_widget)
159 return;
142 160
143 if (!rect.isEmpty()) { 161 if (!rect.isEmpty()) {
144 #if WEBKIT_USING_CG 162 #if WEBKIT_USING_CG
145 GraphicsContext gc(canvas); 163 GraphicsContext gc(canvas);
146 #elif WEBKIT_USING_SKIA 164 #elif WEBKIT_USING_SKIA
147 PlatformContextSkia context(canvas); 165 PlatformContextSkia context(canvas);
148 // PlatformGraphicsContext is actually a pointer to PlatformContextSkia. 166 // PlatformGraphicsContext is actually a pointer to PlatformContextSkia.
149 GraphicsContext gc(reinterpret_cast<PlatformGraphicsContext*>(&context)); 167 GraphicsContext gc(reinterpret_cast<PlatformGraphicsContext*>(&context));
150 #else 168 #else
151 notImplemented(); 169 notImplemented();
152 #endif 170 #endif
153 widget_->paint(&gc, webkit_glue::WebRectToIntRect(rect)); 171 m_widget->paint(&gc, rect);
154 } 172 }
155 } 173 }
156 174
157 bool WebPopupMenuImpl::handleInputEvent(const WebInputEvent& input_event) { 175 bool WebPopupMenuImpl::handleInputEvent(const WebInputEvent& inputEvent)
158 if (!widget_) 176 {
159 return false; 177 if (!m_widget)
178 return false;
160 179
161 // TODO (jcampan): WebKit seems to always return false on mouse events 180 // TODO (jcampan): WebKit seems to always return false on mouse events
162 // methods. For now we'll assume it has processed them (as we are only 181 // methods. For now we'll assume it has processed them (as we are only
163 // interested in whether keyboard events are processed). 182 // interested in whether keyboard events are processed).
164 switch (input_event.type) { 183 switch (inputEvent.type) {
165 case WebInputEvent::MouseMove: 184 case WebInputEvent::MouseMove:
166 MouseMove(*static_cast<const WebMouseEvent*>(&input_event)); 185 MouseMove(*static_cast<const WebMouseEvent*>(&inputEvent));
167 return true; 186 return true;
168 187
169 case WebInputEvent::MouseLeave: 188 case WebInputEvent::MouseLeave:
170 MouseLeave(*static_cast<const WebMouseEvent*>(&input_event)); 189 MouseLeave(*static_cast<const WebMouseEvent*>(&inputEvent));
171 return true; 190 return true;
172 191
173 case WebInputEvent::MouseWheel: 192 case WebInputEvent::MouseWheel:
174 MouseWheel(*static_cast<const WebMouseWheelEvent*>(&input_event)); 193 MouseWheel(*static_cast<const WebMouseWheelEvent*>(&inputEvent));
175 return true; 194 return true;
176 195
177 case WebInputEvent::MouseDown: 196 case WebInputEvent::MouseDown:
178 MouseDown(*static_cast<const WebMouseEvent*>(&input_event)); 197 MouseDown(*static_cast<const WebMouseEvent*>(&inputEvent));
179 return true; 198 return true;
180 199
181 case WebInputEvent::MouseUp: 200 case WebInputEvent::MouseUp:
182 MouseUp(*static_cast<const WebMouseEvent*>(&input_event)); 201 MouseUp(*static_cast<const WebMouseEvent*>(&inputEvent));
183 return true; 202 return true;
184 203
185 // In Windows, RawKeyDown only has information about the physical key, but 204 // In Windows, RawKeyDown only has information about the physical key, but
186 // for "selection", we need the information about the character the key 205 // for "selection", we need the information about the character the key
187 // translated into. For English, the physical key value and the character 206 // translated into. For English, the physical key value and the character
188 // value are the same, hence, "selection" works for English. But for other 207 // value are the same, hence, "selection" works for English. But for other
189 // languages, such as Hebrew, the character value is different from the 208 // languages, such as Hebrew, the character value is different from the
190 // physical key value. Thus, without accepting Char event type which 209 // physical key value. Thus, without accepting Char event type which
191 // contains the key's character value, the "selection" won't work for 210 // contains the key's character value, the "selection" won't work for
192 // non-English languages, such as Hebrew. 211 // non-English languages, such as Hebrew.
193 case WebInputEvent::RawKeyDown: 212 case WebInputEvent::RawKeyDown:
194 case WebInputEvent::KeyDown: 213 case WebInputEvent::KeyDown:
195 case WebInputEvent::KeyUp: 214 case WebInputEvent::KeyUp:
196 case WebInputEvent::Char: 215 case WebInputEvent::Char:
197 return KeyEvent(*static_cast<const WebKeyboardEvent*>(&input_event)); 216 return KeyEvent(*static_cast<const WebKeyboardEvent*>(&inputEvent));
198 217
199 default: 218 default:
200 break; 219 break;
201 } 220 }
202 return false; 221 return false;
203 } 222 }
204 223
205 void WebPopupMenuImpl::mouseCaptureLost() { 224 void WebPopupMenuImpl::mouseCaptureLost()
225 {
206 } 226 }
207 227
208 void WebPopupMenuImpl::setFocus(bool enable) { 228 void WebPopupMenuImpl::setFocus(bool enable)
229 {
209 } 230 }
210 231
211 bool WebPopupMenuImpl::handleCompositionEvent( 232 bool WebPopupMenuImpl::handleCompositionEvent(
212 WebCompositionCommand command, 233 WebCompositionCommand command, int cursorPosition, int targetStart,
213 int cursor_position, 234 int targetEnd, const WebString& imeString)
214 int target_start, 235 {
215 int target_end, 236 return false;
216 const WebString& ime_string) {
217 return false;
218 } 237 }
219 238
220 bool WebPopupMenuImpl::queryCompositionStatus(bool* enabled, 239 bool WebPopupMenuImpl::queryCompositionStatus(bool* enabled, WebRect* caretRect)
221 WebRect* caret_rect) { 240 {
222 return false; 241 return false;
223 } 242 }
224 243
225 void WebPopupMenuImpl::setTextDirection(WebTextDirection direction) { 244 void WebPopupMenuImpl::setTextDirection(WebTextDirection direction)
245 {
226 } 246 }
227 247
248
228 //----------------------------------------------------------------------------- 249 //-----------------------------------------------------------------------------
229 // WebCore::HostWindow 250 // WebCore::HostWindow
230 251
231 void WebPopupMenuImpl::repaint(const WebCore::IntRect& paint_rect, 252 void WebPopupMenuImpl::repaint(const IntRect& paintRect,
232 bool content_changed, 253 bool contentChanged,
233 bool immediate, 254 bool immediate,
234 bool repaint_content_only) { 255 bool repaintContentOnly)
235 // Ignore spurious calls. 256 {
236 if (!content_changed || paint_rect.isEmpty()) 257 // Ignore spurious calls.
237 return; 258 if (!contentChanged || paintRect.isEmpty())
238 if (client_) 259 return;
239 client_->didInvalidateRect(webkit_glue::IntRectToWebRect(paint_rect)); 260 if (m_client)
261 m_client->didInvalidateRect(paintRect);
240 } 262 }
241 263
242 void WebPopupMenuImpl::scroll(const WebCore::IntSize& scroll_delta, 264 void WebPopupMenuImpl::scroll(const IntSize& scrollDelta,
243 const WebCore::IntRect& scroll_rect, 265 const IntRect& scrollRect,
244 const WebCore::IntRect& clip_rect) { 266 const IntRect& clipRect)
245 if (client_) { 267 {
246 int dx = scroll_delta.width(); 268 if (m_client) {
247 int dy = scroll_delta.height(); 269 int dx = scrollDelta.width();
248 client_->didScrollRect(dx, dy, webkit_glue::IntRectToWebRect(clip_rect)); 270 int dy = scrollDelta.height();
249 } 271 m_client->didScrollRect(dx, dy, clipRect);
272 }
250 } 273 }
251 274
252 WebCore::IntPoint WebPopupMenuImpl::screenToWindow( 275 IntPoint WebPopupMenuImpl::screenToWindow(const IntPoint& point) const
253 const WebCore::IntPoint& point) const { 276 {
254 notImplemented(); 277 notImplemented();
255 return WebCore::IntPoint(); 278 return IntPoint();
256 } 279 }
257 280
258 WebCore::IntRect WebPopupMenuImpl::windowToScreen( 281 IntRect WebPopupMenuImpl::windowToScreen(const IntRect& rect) const
259 const WebCore::IntRect& rect) const { 282 {
260 notImplemented(); 283 notImplemented();
261 return WebCore::IntRect(); 284 return IntRect();
262 } 285 }
263 286
264 void WebPopupMenuImpl::scrollRectIntoView( 287 void WebPopupMenuImpl::scrollRectIntoView(const IntRect&, const ScrollView*) const
265 const WebCore::IntRect&, const WebCore::ScrollView*) const { 288 {
266 // Nothing to be done here since we do not have the concept of a container 289 // Nothing to be done here since we do not have the concept of a container
267 // that implements its own scrolling. 290 // that implements its own scrolling.
268 } 291 }
269 292
270 void WebPopupMenuImpl::scrollbarsModeDidChange() const { 293 void WebPopupMenuImpl::scrollbarsModeDidChange() const
271 // Nothing to be done since we have no concept of different scrollbar modes. 294 {
295 // Nothing to be done since we have no concept of different scrollbar modes.
272 } 296 }
273 297
274 //----------------------------------------------------------------------------- 298 //-----------------------------------------------------------------------------
275 // WebCore::FramelessScrollViewClient 299 // WebCore::FramelessScrollViewClient
276 300
277 void WebPopupMenuImpl::popupClosed(WebCore::FramelessScrollView* widget) { 301 void WebPopupMenuImpl::popupClosed(FramelessScrollView* widget)
278 ASSERT(widget == widget_); 302 {
279 if (widget_) { 303 ASSERT(widget == m_widget);
280 widget_->setClient(NULL); 304 if (m_widget) {
281 widget_ = NULL; 305 m_widget->setClient(0);
282 } 306 m_widget = 0;
283 client_->closeWidgetSoon(); 307 }
308 m_client->closeWidgetSoon();
284 } 309 }
310
311 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698