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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 10908127: events: Move EventTarget into Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 host_->SetInputMethodActive(false); 1160 host_->SetInputMethodActive(false);
1161 1161
1162 // If we lose the focus while fullscreen, close the window; Pepper Flash won't 1162 // If we lose the focus while fullscreen, close the window; Pepper Flash won't
1163 // do it for us (unlike NPAPI Flash). 1163 // do it for us (unlike NPAPI Flash).
1164 if (is_fullscreen_ && !in_shutdown_) { 1164 if (is_fullscreen_ && !in_shutdown_) {
1165 in_shutdown_ = true; 1165 in_shutdown_ = true;
1166 host_->Shutdown(); 1166 host_->Shutdown();
1167 } 1167 }
1168 } 1168 }
1169 1169
1170 bool RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { 1170 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
1171 if (mouse_locked_)
1172 return ui::kCursorNone;
1173 return current_cursor_.GetNativeCursor();
1174 }
1175
1176 int RenderWidgetHostViewAura::GetNonClientComponent(
1177 const gfx::Point& point) const {
1178 return HTCLIENT;
1179 }
1180
1181 bool RenderWidgetHostViewAura::ShouldDescendIntoChildForEventHandling(
1182 aura::Window* child,
1183 const gfx::Point& location) {
1184 return true;
1185 }
1186
1187 bool RenderWidgetHostViewAura::CanFocus() {
1188 return popup_type_ == WebKit::WebPopupTypeNone;
1189 }
1190
1191 void RenderWidgetHostViewAura::OnCaptureLost() {
1192 host_->LostCapture();
1193 }
1194
1195 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) {
1196 paint_canvas_ = canvas;
1197 BackingStore* backing_store = host_->GetBackingStore(true);
1198 paint_canvas_ = NULL;
1199 if (backing_store) {
1200 static_cast<BackingStoreAura*>(backing_store)->SkiaShowRect(gfx::Point(),
1201 canvas);
1202 } else if (aura::Env::GetInstance()->render_white_bg()) {
1203 canvas->DrawColor(SK_ColorWHITE);
1204 }
1205 }
1206
1207 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
1208 float device_scale_factor) {
1209 if (!host_)
1210 return;
1211
1212 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>(
1213 host_->GetBackingStore(false));
1214 if (backing_store) // NULL in hardware path.
1215 backing_store->ScaleFactorChanged(device_scale_factor);
1216
1217 host_->SetDeviceScaleFactor(device_scale_factor);
1218 current_cursor_.SetScaleFactor(device_scale_factor);
1219 }
1220
1221 void RenderWidgetHostViewAura::OnWindowDestroying() {
1222 }
1223
1224 void RenderWidgetHostViewAura::OnWindowDestroyed() {
1225 host_->ViewDestroyed();
1226 delete this;
1227 }
1228
1229 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1230 }
1231
1232 bool RenderWidgetHostViewAura::HasHitTestMask() const {
1233 return false;
1234 }
1235
1236 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const {
1237 }
1238
1239 ////////////////////////////////////////////////////////////////////////////////
1240 // RenderWidgetHostViewAura, ui::EventHandler implementation:
1241
1242 ui::EventResult RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
1171 TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnKeyEvent"); 1243 TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnKeyEvent");
1172 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab() && 1244 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab() &&
1173 popup_child_host_view_->OnKeyEvent(event)) 1245 popup_child_host_view_->OnKeyEvent(event))
1174 return true; 1246 return ui::ER_HANDLED;
1175 1247
1176 // We need to handle the Escape key for Pepper Flash. 1248 // We need to handle the Escape key for Pepper Flash.
1177 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { 1249 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
1178 if (!in_shutdown_) { 1250 if (!in_shutdown_) {
1179 in_shutdown_ = true; 1251 in_shutdown_ = true;
1180 host_->Shutdown(); 1252 host_->Shutdown();
1181 } 1253 }
1182 } else { 1254 } else {
1183 // We don't have to communicate with an input method here. 1255 // We don't have to communicate with an input method here.
1184 if (!event->HasNativeEvent()) { 1256 if (!event->HasNativeEvent()) {
1185 // Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event. 1257 // Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event.
1186 NativeWebKeyboardEvent webkit_event(event->type(), 1258 NativeWebKeyboardEvent webkit_event(event->type(),
1187 false /* is_char */, 1259 false /* is_char */,
1188 event->GetCharacter(), 1260 event->GetCharacter(),
1189 event->flags(), 1261 event->flags(),
1190 base::Time::Now().ToDoubleT()); 1262 base::Time::Now().ToDoubleT());
1191 host_->ForwardKeyboardEvent(webkit_event); 1263 host_->ForwardKeyboardEvent(webkit_event);
1192 } else { 1264 } else {
1193 NativeWebKeyboardEvent webkit_event(event); 1265 NativeWebKeyboardEvent webkit_event(event);
1194 host_->ForwardKeyboardEvent(webkit_event); 1266 host_->ForwardKeyboardEvent(webkit_event);
1195 } 1267 }
1196 } 1268 }
1197 return true; 1269 return ui::ER_HANDLED;
1198 } 1270 }
1199 1271
1200 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { 1272 ui::EventResult RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
1201 if (mouse_locked_)
1202 return ui::kCursorNone;
1203 return current_cursor_.GetNativeCursor();
1204 }
1205
1206 int RenderWidgetHostViewAura::GetNonClientComponent(
1207 const gfx::Point& point) const {
1208 return HTCLIENT;
1209 }
1210
1211 bool RenderWidgetHostViewAura::ShouldDescendIntoChildForEventHandling(
1212 aura::Window* child,
1213 const gfx::Point& location) {
1214 return true;
1215 }
1216
1217 bool RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
1218 TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnMouseEvent"); 1273 TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnMouseEvent");
1219 if (mouse_locked_) { 1274 if (mouse_locked_) {
1220 WebKit::WebMouseEvent mouse_event = MakeWebMouseEvent(event); 1275 WebKit::WebMouseEvent mouse_event = MakeWebMouseEvent(event);
1221 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); 1276 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint());
1222 1277
1223 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || 1278 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED ||
1224 event->type() == ui::ET_MOUSE_DRAGGED) && 1279 event->type() == ui::ET_MOUSE_DRAGGED) &&
1225 mouse_event.x == center.x() && mouse_event.y == center.y(); 1280 mouse_event.x == center.x() && mouse_event.y == center.y();
1226 1281
1227 ModifyEventMovementAndCoords(&mouse_event); 1282 ModifyEventMovementAndCoords(&mouse_event);
1228 1283
1229 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; 1284 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_;
1230 if (should_not_forward) { 1285 if (should_not_forward) {
1231 synthetic_move_sent_ = false; 1286 synthetic_move_sent_ = false;
1232 } else { 1287 } else {
1233 // Check if the mouse has reached the border and needs to be centered. 1288 // Check if the mouse has reached the border and needs to be centered.
1234 if (ShouldMoveToCenter()) { 1289 if (ShouldMoveToCenter()) {
1235 synthetic_move_sent_ = true; 1290 synthetic_move_sent_ = true;
1236 window_->MoveCursorTo(center); 1291 window_->MoveCursorTo(center);
1237 } 1292 }
1238 1293
1239 // Forward event to renderer. 1294 // Forward event to renderer.
1240 if (CanRendererHandleEvent(event)) 1295 if (CanRendererHandleEvent(event))
1241 host_->ForwardMouseEvent(mouse_event); 1296 host_->ForwardMouseEvent(mouse_event);
1242 } 1297 }
1243 1298
1244 return false; 1299 return ui::ER_UNHANDLED;
1245 } 1300 }
1246 1301
1247 if (event->type() == ui::ET_MOUSEWHEEL) { 1302 if (event->type() == ui::ET_MOUSEWHEEL) {
1248 WebKit::WebMouseWheelEvent mouse_wheel_event = 1303 WebKit::WebMouseWheelEvent mouse_wheel_event =
1249 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event)); 1304 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event));
1250 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) 1305 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0)
1251 host_->ForwardWheelEvent(mouse_wheel_event); 1306 host_->ForwardWheelEvent(mouse_wheel_event);
1252 } else if (event->type() == ui::ET_SCROLL) { 1307 } else if (event->type() == ui::ET_SCROLL) {
1253 WebKit::WebGestureEvent gesture_event = 1308 WebKit::WebGestureEvent gesture_event =
1254 MakeWebGestureEventFlingCancel(); 1309 MakeWebGestureEventFlingCancel();
(...skipping 28 matching lines...) Expand all
1283 default: 1338 default:
1284 break; 1339 break;
1285 } 1340 }
1286 1341
1287 // Needed to propagate mouse event to native_tab_contents_view_aura. 1342 // Needed to propagate mouse event to native_tab_contents_view_aura.
1288 // TODO(pkotwicz): Find a better way of doing this. 1343 // TODO(pkotwicz): Find a better way of doing this.
1289 if (window_->parent()->delegate()) 1344 if (window_->parent()->delegate())
1290 window_->parent()->delegate()->OnMouseEvent(event); 1345 window_->parent()->delegate()->OnMouseEvent(event);
1291 1346
1292 // Return true so that we receive released/drag events. 1347 // Return true so that we receive released/drag events.
1293 return true; 1348 return ui::ER_HANDLED;
1294 } 1349 }
1295 1350
1296 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent( 1351 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent(
1297 ui::TouchEvent* event) { 1352 ui::TouchEvent* event) {
1298 TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnTouchEvent"); 1353 TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnTouchEvent");
1299 // Update the touch event first. 1354 // Update the touch event first.
1300 WebKit::WebTouchPoint* point = UpdateWebTouchEvent(event, 1355 WebKit::WebTouchPoint* point = UpdateWebTouchEvent(event,
1301 &touch_event_); 1356 &touch_event_);
1302 1357
1303 // Forward the touch event only if a touch point was updated, and there's a 1358 // Forward the touch event only if a touch point was updated, and there's a
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 delegate->HandleGestureEnd(); 1410 delegate->HandleGestureEnd();
1356 } 1411 }
1357 1412
1358 // If a gesture is not processed by the webpage, then WebKit processes it 1413 // If a gesture is not processed by the webpage, then WebKit processes it
1359 // (e.g. generates synthetic mouse events). So CONSUMED should be returned 1414 // (e.g. generates synthetic mouse events). So CONSUMED should be returned
1360 // from here to avoid any duplicate synthetic mouse-events being generated 1415 // from here to avoid any duplicate synthetic mouse-events being generated
1361 // from aura. 1416 // from aura.
1362 return ui::ER_CONSUMED; 1417 return ui::ER_CONSUMED;
1363 } 1418 }
1364 1419
1365 bool RenderWidgetHostViewAura::CanFocus() {
1366 return popup_type_ == WebKit::WebPopupTypeNone;
1367 }
1368
1369 void RenderWidgetHostViewAura::OnCaptureLost() {
1370 host_->LostCapture();
1371 }
1372
1373 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) {
1374 paint_canvas_ = canvas;
1375 BackingStore* backing_store = host_->GetBackingStore(true);
1376 paint_canvas_ = NULL;
1377 if (backing_store) {
1378 static_cast<BackingStoreAura*>(backing_store)->SkiaShowRect(gfx::Point(),
1379 canvas);
1380 } else if (aura::Env::GetInstance()->render_white_bg()) {
1381 canvas->DrawColor(SK_ColorWHITE);
1382 }
1383 }
1384
1385 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
1386 float device_scale_factor) {
1387 if (!host_)
1388 return;
1389
1390 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>(
1391 host_->GetBackingStore(false));
1392 if (backing_store) // NULL in hardware path.
1393 backing_store->ScaleFactorChanged(device_scale_factor);
1394
1395 host_->SetDeviceScaleFactor(device_scale_factor);
1396 current_cursor_.SetScaleFactor(device_scale_factor);
1397 }
1398
1399 void RenderWidgetHostViewAura::OnWindowDestroying() {
1400 }
1401
1402 void RenderWidgetHostViewAura::OnWindowDestroyed() {
1403 host_->ViewDestroyed();
1404 delete this;
1405 }
1406
1407 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1408 }
1409
1410 bool RenderWidgetHostViewAura::HasHitTestMask() const {
1411 return false;
1412 }
1413
1414 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const {
1415 }
1416
1417 //////////////////////////////////////////////////////////////////////////////// 1420 ////////////////////////////////////////////////////////////////////////////////
1418 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation: 1421 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation:
1419 1422
1420 bool RenderWidgetHostViewAura::ShouldActivate(const ui::Event* event) { 1423 bool RenderWidgetHostViewAura::ShouldActivate(const ui::Event* event) {
1421 bool activate = false; 1424 bool activate = false;
1422 if (event) { 1425 if (event) {
1423 if (event->type() == ui::ET_MOUSE_PRESSED) { 1426 if (event->type() == ui::ET_MOUSE_PRESSED) {
1424 activate = true; 1427 activate = true;
1425 } else if (event->type() == ui::ET_GESTURE_BEGIN) { 1428 } else if (event->type() == ui::ET_GESTURE_BEGIN) {
1426 activate = static_cast<const ui::GestureEvent*>(event)-> 1429 activate = static_cast<const ui::GestureEvent*>(event)->
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 RenderWidgetHost* widget) { 1679 RenderWidgetHost* widget) {
1677 return new RenderWidgetHostViewAura(widget); 1680 return new RenderWidgetHostViewAura(widget);
1678 } 1681 }
1679 1682
1680 // static 1683 // static
1681 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 1684 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
1682 GetScreenInfoForWindow(results, NULL); 1685 GetScreenInfoForWindow(results, NULL);
1683 } 1686 }
1684 1687
1685 } // namespace content 1688 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('k') | content/browser/web_contents/web_contents_view_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698