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

Side by Side Diff: webkit/glue/webpopupmenu_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698