| Index: ash/host/ash_window_tree_host_x11.cc
|
| diff --git a/ash/host/ash_window_tree_host_x11.cc b/ash/host/ash_window_tree_host_x11.cc
|
| index e49e9617727490faa3b400f4998022d46c448f86..f45cb7d74adecaa5d1b40830d200433ca398b8cd 100644
|
| --- a/ash/host/ash_window_tree_host_x11.cc
|
| +++ b/ash/host/ash_window_tree_host_x11.cc
|
| @@ -14,162 +14,26 @@
|
|
|
| #include "ash/host/root_window_transformer.h"
|
| #include "base/basictypes.h"
|
| -#include "base/command_line.h"
|
| -#include "base/strings/string_number_conversions.h"
|
| -#include "base/strings/string_util.h"
|
| #include "base/sys_info.h"
|
| #include "ui/aura/client/screen_position_client.h"
|
| #include "ui/aura/env.h"
|
| #include "ui/aura/window.h"
|
| #include "ui/base/x/x11_util.h"
|
| #include "ui/events/event.h"
|
| -#include "ui/events/event_switches.h"
|
| #include "ui/events/event_utils.h"
|
| -#include "ui/events/platform/platform_event_observer.h"
|
| -#include "ui/events/platform/x11/x11_event_source.h"
|
| #include "ui/events/x/device_data_manager.h"
|
| #include "ui/events/x/device_list_cache_x.h"
|
| #include "ui/events/x/touch_factory_x11.h"
|
| -
|
| #include "ui/gfx/rect.h"
|
| #include "ui/gfx/screen.h"
|
|
|
| namespace ash {
|
|
|
| -// Accomplishes 2 tasks concerning touch event calibration:
|
| -// 1. Being a message-pump observer,
|
| -// routes all the touch events to the X root window,
|
| -// where they can be calibrated later.
|
| -// 2. Has the Calibrate method that does the actual bezel calibration,
|
| -// when invoked from X root window's event dispatcher.
|
| -class AshWindowTreeHostX11::TouchEventCalibrate
|
| - : public ui::PlatformEventObserver {
|
| - public:
|
| - TouchEventCalibrate() : left_(0), right_(0), top_(0), bottom_(0) {
|
| - if (ui::PlatformEventSource::GetInstance())
|
| - ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
|
| -#if defined(USE_XI2_MT)
|
| - std::vector<std::string> parts;
|
| - if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
| - switches::kTouchCalibration),
|
| - ",",
|
| - &parts) >= 4) {
|
| - if (!base::StringToInt(parts[0], &left_))
|
| - DLOG(ERROR) << "Incorrect left border calibration value passed.";
|
| - if (!base::StringToInt(parts[1], &right_))
|
| - DLOG(ERROR) << "Incorrect right border calibration value passed.";
|
| - if (!base::StringToInt(parts[2], &top_))
|
| - DLOG(ERROR) << "Incorrect top border calibration value passed.";
|
| - if (!base::StringToInt(parts[3], &bottom_))
|
| - DLOG(ERROR) << "Incorrect bottom border calibration value passed.";
|
| - }
|
| -#endif // defined(USE_XI2_MT)
|
| - }
|
| -
|
| - virtual ~TouchEventCalibrate() {
|
| - if (ui::PlatformEventSource::GetInstance())
|
| - ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this);
|
| - }
|
| -
|
| - // Modify the location of the |event|,
|
| - // expanding it from |bounds| to (|bounds| + bezels).
|
| - // Required when touchscreen is bigger than screen (i.e. has bezels),
|
| - // because we receive events in touchscreen coordinates,
|
| - // which need to be expanded when converting to screen coordinates,
|
| - // so that location on bezels will be outside of screen area.
|
| - void Calibrate(ui::TouchEvent* event, const gfx::Rect& bounds) {
|
| -#if defined(USE_XI2_MT)
|
| - int x = event->x();
|
| - int y = event->y();
|
| -
|
| - if (!left_ && !right_ && !top_ && !bottom_)
|
| - return;
|
| -
|
| - const int resolution_x = bounds.width();
|
| - const int resolution_y = bounds.height();
|
| - // The "grace area" (10% in this case) is to make it easier for the user to
|
| - // navigate to the corner.
|
| - const double kGraceAreaFraction = 0.1;
|
| - if (left_ || right_) {
|
| - // Offset the x position to the real
|
| - x -= left_;
|
| - // Check if we are in the grace area of the left side.
|
| - // Note: We might not want to do this when the gesture is locked?
|
| - if (x < 0 && x > -left_ * kGraceAreaFraction)
|
| - x = 0;
|
| - // Check if we are in the grace area of the right side.
|
| - // Note: We might not want to do this when the gesture is locked?
|
| - if (x > resolution_x - left_ &&
|
| - x < resolution_x - left_ + right_ * kGraceAreaFraction)
|
| - x = resolution_x - left_;
|
| - // Scale the screen area back to the full resolution of the screen.
|
| - x = (x * resolution_x) / (resolution_x - (right_ + left_));
|
| - }
|
| - if (top_ || bottom_) {
|
| - // When there is a top bezel we add our border,
|
| - y -= top_;
|
| -
|
| - // Check if we are in the grace area of the top side.
|
| - // Note: We might not want to do this when the gesture is locked?
|
| - if (y < 0 && y > -top_ * kGraceAreaFraction)
|
| - y = 0;
|
| -
|
| - // Check if we are in the grace area of the bottom side.
|
| - // Note: We might not want to do this when the gesture is locked?
|
| - if (y > resolution_y - top_ &&
|
| - y < resolution_y - top_ + bottom_ * kGraceAreaFraction)
|
| - y = resolution_y - top_;
|
| - // Scale the screen area back to the full resolution of the screen.
|
| - y = (y * resolution_y) / (resolution_y - (bottom_ + top_));
|
| - }
|
| -
|
| - // Set the modified coordinate back to the event.
|
| - if (event->root_location() == event->location()) {
|
| - // Usually those will be equal,
|
| - // if not, I am not sure what the correct value should be.
|
| - event->set_root_location(gfx::Point(x, y));
|
| - }
|
| - event->set_location(gfx::Point(x, y));
|
| -#endif // defined(USE_XI2_MT)
|
| - }
|
| -
|
| - private:
|
| - // ui::PlatformEventObserver:
|
| - virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE {
|
| -#if defined(USE_XI2_MT)
|
| - if (event->type == GenericEvent &&
|
| - (event->xgeneric.evtype == XI_TouchBegin ||
|
| - event->xgeneric.evtype == XI_TouchUpdate ||
|
| - event->xgeneric.evtype == XI_TouchEnd)) {
|
| - XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event->xcookie.data);
|
| - xievent->event = xievent->root;
|
| - xievent->event_x = xievent->root_x;
|
| - xievent->event_y = xievent->root_y;
|
| - }
|
| -#endif // defined(USE_XI2_MT)
|
| - }
|
| -
|
| - virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE {}
|
| -
|
| - // The difference in screen's native resolution pixels between
|
| - // the border of the touchscreen and the border of the screen,
|
| - // aka bezel sizes.
|
| - int left_;
|
| - int right_;
|
| - int top_;
|
| - int bottom_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(TouchEventCalibrate);
|
| -};
|
| -
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -// AshWindowTreeHostX11
|
| -
|
| AshWindowTreeHostX11::AshWindowTreeHostX11(const gfx::Rect& initial_bounds)
|
| : WindowTreeHostX11(initial_bounds),
|
| - is_internal_display_(false),
|
| - touch_calibrate_(new TouchEventCalibrate),
|
| - transformer_helper_(this) {
|
| + transformer_helper_(this),
|
| + display_ids_(std::make_pair(gfx::Display::kInvalidDisplayID,
|
| + gfx::Display::kInvalidDisplayID)) {
|
| aura::Env::GetInstance()->AddObserver(this);
|
| }
|
|
|
| @@ -247,7 +111,6 @@ void AshWindowTreeHostX11::UnConfineCursor() {
|
| void AshWindowTreeHostX11::SetRootWindowTransformer(
|
| scoped_ptr<RootWindowTransformer> transformer) {
|
| transformer_helper_.SetRootWindowTransformer(transformer.Pass());
|
| - UpdateIsInternalDisplay();
|
| if (pointer_barriers_) {
|
| UnConfineCursor();
|
| ConfineCursorToRootWindow();
|
| @@ -256,9 +119,13 @@ void AshWindowTreeHostX11::SetRootWindowTransformer(
|
|
|
| aura::WindowTreeHost* AshWindowTreeHostX11::AsWindowTreeHost() { return this; }
|
|
|
| +void AshWindowTreeHostX11::UpdateDisplayID(int64 id1, int64 id2) {
|
| + display_ids_.first = id1;
|
| + display_ids_.second = id2;
|
| +}
|
| +
|
| void AshWindowTreeHostX11::SetBounds(const gfx::Rect& bounds) {
|
| WindowTreeHostX11::SetBounds(bounds);
|
| - UpdateIsInternalDisplay();
|
| if (pointer_barriers_) {
|
| UnConfineCursor();
|
| ConfineCursorToRootWindow();
|
| @@ -288,13 +155,8 @@ void AshWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) {
|
| void AshWindowTreeHostX11::OnWindowInitialized(aura::Window* window) {}
|
|
|
| void AshWindowTreeHostX11::OnHostInitialized(aura::WindowTreeHost* host) {
|
| - // UpdateIsInternalDisplay relies on RootWindowSettings' display_id being set
|
| - // available by the time WED::Init is called. (set in
|
| - // DisplayManager::CreateRootWindowForDisplay)
|
| - // Ready when NotifyHostInitialized is called from WED::Init.
|
| if (host != AsWindowTreeHost())
|
| return;
|
| - UpdateIsInternalDisplay();
|
|
|
| // We have to enable Tap-to-click by default because the cursor is set to
|
| // visible in Shell::InitRootWindowController.
|
| @@ -302,8 +164,6 @@ void AshWindowTreeHostX11::OnHostInitialized(aura::WindowTreeHost* host) {
|
| }
|
|
|
| void AshWindowTreeHostX11::OnConfigureNotify() {
|
| - UpdateIsInternalDisplay();
|
| -
|
| // Always update barrier and mouse location because |bounds_| might
|
| // have already been updated in |SetBounds|.
|
| if (pointer_barriers_) {
|
| @@ -312,29 +172,51 @@ void AshWindowTreeHostX11::OnConfigureNotify() {
|
| }
|
| }
|
|
|
| +bool AshWindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) {
|
| + if(!WindowTreeHostX11::CanDispatchEvent(event))
|
| + return false;
|
| + XEvent* xev = event;
|
| + XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data);
|
| + ui::EventType type = ui::EventTypeFromNative(xev);
|
| + // For touch event, check if the root window is residing on the according
|
| + // touch display.
|
| + switch (type) {
|
| + case ui::ET_TOUCH_MOVED:
|
| + case ui::ET_TOUCH_PRESSED:
|
| + case ui::ET_TOUCH_CANCELLED:
|
| + case ui::ET_TOUCH_RELEASED: {
|
| +#if defined(OS_CHROMEOS)
|
| + int64 touch_display_id =
|
| + ui::DeviceDataManager::GetInstance()->GetDisplayForTouchDevice(
|
| + xiev->deviceid);
|
| + // If we don't have record of display id for this touch device, check
|
| + // that if the event is within the bound of the root window. Note
|
| + // that in multi-monitor case, the event position is in framebuffer
|
| + // space so the bounds check will not work so well.
|
| + if (touch_display_id == gfx::Display::kInvalidDisplayID) {
|
| + if (base::SysInfo::IsRunningOnChromeOS() &&
|
| + !bounds().Contains(ui::EventLocationFromNative(xev)))
|
| + return false;
|
| + } else if (touch_display_id != display_ids_.first &&
|
| + touch_display_id != display_ids_.second) {
|
| + return false;
|
| + }
|
| +#endif // defined(OS_CHROMEOS)
|
| + return true;
|
| + }
|
| + default:
|
| + return true;
|
| + }
|
| +}
|
| +
|
| void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent(
|
| ui::LocatedEvent* event) {
|
| switch (event->type()) {
|
| case ui::ET_TOUCH_MOVED:
|
| case ui::ET_TOUCH_PRESSED:
|
| case ui::ET_TOUCH_CANCELLED:
|
| - case ui::ET_TOUCH_RELEASED: {
|
| - ui::TouchEvent* touchev = static_cast<ui::TouchEvent*>(event);
|
| - if (base::SysInfo::IsRunningOnChromeOS()) {
|
| - // X maps the touch-surface to the size of the X root-window.
|
| - // In multi-monitor setup, Coordinate Transformation Matrix
|
| - // repositions the touch-surface onto part of X root-window
|
| - // containing aura root-window corresponding to the touchscreen.
|
| - // However, if aura root-window has non-zero origin,
|
| - // we need to relocate the event into aura root-window coordinates.
|
| - touchev->Relocate(bounds().origin());
|
| -#if defined(USE_XI2_MT)
|
| - if (is_internal_display_)
|
| - touch_calibrate_->Calibrate(touchev, bounds());
|
| -#endif // defined(USE_XI2_MT)
|
| - }
|
| + case ui::ET_TOUCH_RELEASED:
|
| break;
|
| - }
|
| default: {
|
| aura::Window* root_window = window();
|
| aura::client::ScreenPositionClient* screen_position_client =
|
| @@ -360,14 +242,6 @@ void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent(
|
| SendEventToProcessor(event);
|
| }
|
|
|
| -void AshWindowTreeHostX11::UpdateIsInternalDisplay() {
|
| - aura::Window* root_window = window();
|
| - gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window);
|
| - gfx::Display display = screen->GetDisplayNearestWindow(root_window);
|
| - DCHECK(display.is_valid());
|
| - is_internal_display_ = display.IsInternal();
|
| -}
|
| -
|
| void AshWindowTreeHostX11::SetCrOSTapPaused(bool state) {
|
| if (!ui::IsXInput2Available())
|
| return;
|
|
|