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

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

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

Powered by Google App Engine
This is Rietveld 408576698