Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/renderer_host/backing_store_skia.h" | 8 #include "content/browser/renderer_host/backing_store_skia.h" |
| 9 #include "content/browser/renderer_host/web_input_event_aura.h" | 9 #include "content/browser/renderer_host/web_input_event_aura.h" |
| 10 #include "content/browser/renderer_host/render_widget_host.h" | 10 #include "content/browser/renderer_host/render_widget_host.h" |
| 11 #include "content/public/browser/native_web_keyboard_event.h" | 11 #include "content/public/browser/native_web_keyboard_event.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 13 #include "ui/aura/desktop.h" | 13 #include "ui/aura/desktop.h" |
| 14 #include "ui/aura/event.h" | 14 #include "ui/aura/event.h" |
| 15 #include "ui/aura/hit_test.h" | 15 #include "ui/aura/hit_test.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 | 18 |
| 19 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | 19 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
| 20 #include "base/bind.h" | 20 #include "base/bind.h" |
| 21 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 21 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 22 #include "content/browser/renderer_host/accelerated_surface_container_linux.h" | 22 #include "content/browser/renderer_host/accelerated_surface_container_linux.h" |
| 23 #include "content/common/gpu/gpu_messages.h" | 23 #include "content/common/gpu/gpu_messages.h" |
| 24 #include "ui/gfx/compositor/layer.h" | 24 #include "ui/gfx/compositor/layer.h" |
| 25 #include "ui/gfx/gl/gl_bindings.h" | 25 #include "ui/gfx/gl/gl_bindings.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 using WebKit::WebTouchEvent; | |
| 29 | |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | 32 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
| 31 void AcknowledgeSwapBuffers(int32 route_id, int gpu_host_id) { | 33 void AcknowledgeSwapBuffers(int32 route_id, int gpu_host_id) { |
| 32 // It's possible that gpu_host_id is no longer valid at this point (like if | 34 // It's possible that gpu_host_id is no longer valid at this point (like if |
| 33 // gpu process was restarted after a crash). SendToGpuHost handles this. | 35 // gpu process was restarted after a crash). SendToGpuHost handles this. |
| 34 GpuProcessHostUIShim::SendToGpuHost(gpu_host_id, | 36 GpuProcessHostUIShim::SendToGpuHost(gpu_host_id, |
| 35 new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); | 37 new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); |
| 36 } | 38 } |
| 37 #endif | 39 #endif |
| 38 | 40 |
| 41 WebKit::WebTouchPoint::State TouchPointStateFromEvent( | |
| 42 const aura::TouchEvent* event) { | |
| 43 switch (event->type()) { | |
| 44 case ui::ET_TOUCH_PRESSED: | |
| 45 return WebKit::WebTouchPoint::StatePressed; | |
| 46 case ui::ET_TOUCH_RELEASED: | |
| 47 return WebKit::WebTouchPoint::StateReleased; | |
| 48 case ui::ET_TOUCH_MOVED: | |
| 49 return WebKit::WebTouchPoint::StateMoved; | |
| 50 case ui::ET_TOUCH_CANCELLED: | |
| 51 return WebKit::WebTouchPoint::StateCancelled; | |
| 52 default: | |
| 53 return WebKit::WebTouchPoint::StateUndefined; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 WebKit::WebInputEvent::Type TouchEventTypeFromEvent( | |
| 58 const aura::TouchEvent* event) { | |
| 59 switch (event->type()) { | |
| 60 case ui::ET_TOUCH_PRESSED: | |
| 61 return WebKit::WebInputEvent::TouchStart; | |
| 62 case ui::ET_TOUCH_RELEASED: | |
| 63 return WebKit::WebInputEvent::TouchEnd; | |
| 64 case ui::ET_TOUCH_MOVED: | |
| 65 return WebKit::WebInputEvent::TouchMove; | |
| 66 case ui::ET_TOUCH_CANCELLED: | |
| 67 return WebKit::WebInputEvent::TouchCancel; | |
| 68 default: | |
| 69 return WebKit::WebInputEvent::Undefined; | |
| 70 } | |
| 71 } | |
| 72 | |
| 39 } // namespace | 73 } // namespace |
| 40 | 74 |
| 41 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
| 42 // RenderWidgetHostViewAura, public: | 76 // RenderWidgetHostViewAura, public: |
| 43 | 77 |
| 44 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) | 78 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) |
| 45 : host_(host), | 79 : host_(host), |
| 46 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 80 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
| 47 is_loading_(false) { | 81 is_loading_(false) { |
| 48 host_->SetView(this); | 82 host_->SetView(this); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event)); | 386 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event)); |
| 353 else | 387 else |
| 354 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event)); | 388 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event)); |
| 355 | 389 |
| 356 // Return true so that we receive released/drag events. | 390 // Return true so that we receive released/drag events. |
| 357 return true; | 391 return true; |
| 358 } | 392 } |
| 359 | 393 |
| 360 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent( | 394 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent( |
| 361 aura::TouchEvent* event) { | 395 aura::TouchEvent* event) { |
| 362 NOTIMPLEMENTED(); | 396 // Update the list of touch points first. |
| 363 return ui::TOUCH_STATUS_UNKNOWN; | 397 WebKit::WebTouchPoint* point = NULL; |
|
Ben Goodger (Google)
2011/10/25 15:00:30
Can we do this in a separate factory function a la
sadrul
2011/10/25 15:09:45
I was going to do this like the other functions, b
| |
| 398 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; | |
| 399 | |
| 400 switch (event->type()) { | |
| 401 case ui::ET_TOUCH_PRESSED: | |
| 402 // Add a new touch point. | |
| 403 if (touch_event_.touchesLength < WebTouchEvent::touchesLengthCap) { | |
| 404 point = &touch_event_.touches[touch_event_.touchesLength++]; | |
| 405 point->id = event->touch_id(); | |
| 406 | |
| 407 if (touch_event_.touchesLength == 1) { | |
| 408 // A new touch sequence has started. | |
| 409 status = ui::TOUCH_STATUS_START; | |
| 410 } | |
| 411 } | |
| 412 break; | |
| 413 case ui::ET_TOUCH_RELEASED: | |
| 414 case ui::ET_TOUCH_CANCELLED: | |
| 415 case ui::ET_TOUCH_MOVED: { | |
| 416 // The touch point should have been added to the event from an earlier | |
| 417 // _PRESSED event. So find that. | |
| 418 // At the moment, only a maximum of 4 touch-points are allowed. So a | |
| 419 // simple loop should be sufficient. | |
| 420 for (unsigned i = 0; i < touch_event_.touchesLength; ++i) { | |
| 421 point = touch_event_.touches + i; | |
| 422 if (point->id == event->touch_id()) | |
| 423 break; | |
| 424 point = NULL; | |
| 425 } | |
| 426 break; | |
| 427 } | |
| 428 default: | |
| 429 DLOG(WARNING) << "Unknown touch event " << event->type(); | |
| 430 break; | |
| 431 } | |
| 432 | |
| 433 if (!point) | |
| 434 return ui::TOUCH_STATUS_UNKNOWN; | |
| 435 | |
| 436 if (status != ui::TOUCH_STATUS_START) | |
| 437 status = ui::TOUCH_STATUS_CONTINUE; | |
| 438 | |
| 439 point->radiusX = event->radius_x(); | |
| 440 point->radiusY = event->radius_y(); | |
| 441 point->rotationAngle = event->rotation_angle(); | |
| 442 point->force = event->force(); | |
| 443 | |
| 444 // Update the location and state of the point. | |
| 445 point->state = TouchPointStateFromEvent(event); | |
| 446 if (point->state == WebKit::WebTouchPoint::StateMoved) { | |
| 447 // It is possible for badly written touch drivers to emit Move events even | |
| 448 // when the touch location hasn't changed. In such cases, consume the event | |
| 449 // and pretend nothing happened. | |
| 450 if (point->position.x == event->x() && point->position.y == event->y()) | |
| 451 return status; | |
| 452 } | |
| 453 point->position.x = event->x(); | |
| 454 point->position.y = event->y(); | |
| 455 | |
| 456 // TODO(sad): Convert to screen coordinates. | |
| 457 point->screenPosition.x = point->position.x; | |
| 458 point->screenPosition.y = point->position.y; | |
| 459 | |
| 460 // Mark the rest of the points as stationary. | |
| 461 for (unsigned i = 0; i < touch_event_.touchesLength; ++i) { | |
| 462 WebKit::WebTouchPoint* iter = touch_event_.touches + i; | |
| 463 if (iter != point) | |
| 464 iter->state = WebKit::WebTouchPoint::StateStationary; | |
| 465 } | |
| 466 | |
| 467 // Update the type of the touch event. | |
| 468 touch_event_.type = TouchEventTypeFromEvent(event); | |
| 469 touch_event_.timeStampSeconds = event->time_stamp().ToDoubleT(); | |
| 470 | |
| 471 // The event and all the touches have been updated. Dispatch. | |
| 472 host_->ForwardTouchEvent(touch_event_); | |
| 473 | |
| 474 // If the touch was released, then remove it from the list of touch points. | |
| 475 if (event->type() == ui::ET_TOUCH_RELEASED) { | |
| 476 --touch_event_.touchesLength; | |
| 477 for (unsigned i = point - touch_event_.touches; | |
| 478 i < touch_event_.touchesLength; | |
| 479 ++i) { | |
| 480 touch_event_.touches[i] = touch_event_.touches[i + 1]; | |
| 481 } | |
| 482 if (touch_event_.touchesLength == 0) | |
| 483 status = ui::TOUCH_STATUS_END; | |
| 484 } else if (event->type() == ui::ET_TOUCH_CANCELLED) { | |
| 485 status = ui::TOUCH_STATUS_CANCEL; | |
| 486 } | |
| 487 | |
| 488 return status; | |
| 364 } | 489 } |
| 365 | 490 |
| 366 bool RenderWidgetHostViewAura::ShouldActivate(aura::Event* event) { | 491 bool RenderWidgetHostViewAura::ShouldActivate(aura::Event* event) { |
| 367 return false; | 492 return false; |
| 368 } | 493 } |
| 369 | 494 |
| 370 void RenderWidgetHostViewAura::OnActivated() { | 495 void RenderWidgetHostViewAura::OnActivated() { |
| 371 } | 496 } |
| 372 | 497 |
| 373 void RenderWidgetHostViewAura::OnLostActive() { | 498 void RenderWidgetHostViewAura::OnLostActive() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 | 543 |
| 419 #if !defined(TOUCH_UI) | 544 #if !defined(TOUCH_UI) |
| 420 //////////////////////////////////////////////////////////////////////////////// | 545 //////////////////////////////////////////////////////////////////////////////// |
| 421 // RenderWidgetHostViewAura, private: | 546 // RenderWidgetHostViewAura, private: |
| 422 | 547 |
| 423 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { | 548 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { |
| 424 //NOTIMPLEMENTED(); | 549 //NOTIMPLEMENTED(); |
| 425 // TODO(beng): See RenderWidgetHostViewWin. | 550 // TODO(beng): See RenderWidgetHostViewWin. |
| 426 } | 551 } |
| 427 #endif | 552 #endif |
| OLD | NEW |