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

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

Powered by Google App Engine
This is Rietveld 408576698