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

Unified Diff: ui/aura/window_tree_host_x11.cc

Issue 201573015: Introdcue AshWindowTreeHost and move ash/chrome specific code in WTH to ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/aura/window_tree_host_x11.cc
diff --git a/ui/aura/window_tree_host_x11.cc b/ui/aura/window_tree_host_x11.cc
index 525694b793aca1993f6fcc5efd95f0461c0c769e..94a5c4eb06e66fc40e3c243ba5af9cb963ce4a3d 100644
--- a/ui/aura/window_tree_host_x11.cc
+++ b/ui/aura/window_tree_host_x11.cc
@@ -6,7 +6,6 @@
#include <strings.h>
#include <X11/cursorfont.h>
-#include <X11/extensions/Xfixes.h>
#include <X11/extensions/XInput2.h>
#include <X11/extensions/Xrandr.h>
#include <X11/Xatom.h>
@@ -27,8 +26,8 @@
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "ui/aura/client/cursor_client.h"
-#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
+#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/ui_base_switches.h"
@@ -108,136 +107,6 @@ bool default_override_redirect = false;
} // namespace
-namespace internal {
-
-// 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 TouchEventCalibrate : public base::MessagePumpObserver {
- public:
- TouchEventCalibrate()
- : left_(0),
- right_(0),
- top_(0),
- bottom_(0) {
- base::MessageLoopForUI::current()->AddObserver(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() {
- base::MessageLoopForUI::current()->RemoveObserver(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:
- // Overridden from base::MessagePumpObserver:
- virtual void WillProcessEvent(const base::NativeEvent& 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 base::NativeEvent& 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);
-};
-
-} // namespace internal
-
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostX11
@@ -248,8 +117,6 @@ WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds)
current_cursor_(ui::kCursorNull),
window_mapped_(false),
bounds_(bounds),
- is_internal_display_(false),
- touch_calibrate_(new internal::TouchEventCalibrate),
atom_cache_(xdisplay_, kAtomsToCache) {
XSetWindowAttributes swa;
memset(&swa, 0, sizeof(swa));
@@ -308,17 +175,13 @@ WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds)
XRRSelectInput(xdisplay_, x_root_window_,
RRScreenChangeNotifyMask | RROutputChangeNotifyMask);
- Env::GetInstance()->AddObserver(this);
CreateCompositor(GetAcceleratedWidget());
}
WindowTreeHostX11::~WindowTreeHostX11() {
- Env::GetInstance()->RemoveObserver(this);
if (ui::PlatformEventSource::GetInstance())
ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
- UnConfineCursor();
-
DestroyCompositor();
DestroyDispatcher();
XDestroyWindow(xdisplay_, xwindow_);
@@ -351,12 +214,12 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) {
// EnterNotify creates ET_MOUSE_MOVE. Mark as synthesized as this is not
// real mouse move event.
mouse_event.set_flags(mouse_event.flags() | ui::EF_IS_SYNTHESIZED);
- TranslateAndDispatchMouseEvent(&mouse_event);
+ TranslateAndDispatchLocatedEvent(&mouse_event);
break;
}
case LeaveNotify: {
ui::MouseEvent mouse_event(xev);
- TranslateAndDispatchMouseEvent(&mouse_event);
+ TranslateAndDispatchLocatedEvent(&mouse_event);
break;
}
case Expose: {
@@ -380,13 +243,13 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) {
switch (ui::EventTypeFromNative(xev)) {
case ui::ET_MOUSEWHEEL: {
ui::MouseWheelEvent mouseev(xev);
- TranslateAndDispatchMouseEvent(&mouseev);
+ TranslateAndDispatchLocatedEvent(&mouseev);
break;
}
case ui::ET_MOUSE_PRESSED:
case ui::ET_MOUSE_RELEASED: {
ui::MouseEvent mouseev(xev);
- TranslateAndDispatchMouseEvent(&mouseev);
+ TranslateAndDispatchLocatedEvent(&mouseev);
break;
}
case ui::ET_UNKNOWN:
@@ -412,13 +275,7 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) {
bool size_changed = bounds_.size() != bounds.size();
bool origin_changed = bounds_.origin() != bounds.origin();
bounds_ = bounds;
- UpdateIsInternalDisplay();
- // Always update barrier and mouse location because |bounds_| might
- // have already been updated in |SetBounds|.
- if (pointer_barriers_) {
- UnConfineCursor();
- ConfineCursorToRootWindow();
- }
+ OnConfigureNotify();
if (size_changed)
OnHostResized(bounds.size());
if (origin_changed)
@@ -479,7 +336,7 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) {
}
ui::MouseEvent mouseev(xev);
- TranslateAndDispatchMouseEvent(&mouseev);
+ TranslateAndDispatchLocatedEvent(&mouseev);
break;
}
}
@@ -521,10 +378,6 @@ void WindowTreeHostX11::Hide() {
}
}
-void WindowTreeHostX11::ToggleFullScreen() {
- NOTIMPLEMENTED();
-}
-
gfx::Rect WindowTreeHostX11::GetBounds() const {
return bounds_;
}
@@ -560,7 +413,6 @@ void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) {
// (possibly synthetic) ConfigureNotify about the actual size and correct
// |bounds_| later.
bounds_ = bounds;
- UpdateIsInternalDisplay();
if (origin_changed)
OnHostMoved(bounds.origin());
if (size_changed || current_scale != new_scale) {
@@ -570,18 +422,6 @@ void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) {
}
}
-gfx::Insets WindowTreeHostX11::GetInsets() const {
- return insets_;
-}
-
-void WindowTreeHostX11::SetInsets(const gfx::Insets& insets) {
- insets_ = insets;
- if (pointer_barriers_) {
- UnConfineCursor();
- ConfineCursorToRootWindow();
- }
-}
-
gfx::Point WindowTreeHostX11::GetLocationOnNativeScreen() const {
return bounds_.origin();
}
@@ -618,54 +458,6 @@ bool WindowTreeHostX11::QueryMouseLocation(gfx::Point* location_return) {
win_y_return >= 0 && win_y_return < bounds_.height());
}
-bool WindowTreeHostX11::ConfineCursorToRootWindow() {
-#if XFIXES_MAJOR >= 5
- DCHECK(!pointer_barriers_.get());
- if (pointer_barriers_)
- return false;
- pointer_barriers_.reset(new XID[4]);
- gfx::Rect bounds(bounds_);
- bounds.Inset(insets_);
- // Horizontal, top barriers.
- pointer_barriers_[0] = XFixesCreatePointerBarrier(
- xdisplay_, x_root_window_,
- bounds.x(), bounds.y(), bounds.right(), bounds.y(),
- BarrierPositiveY,
- 0, XIAllDevices);
- // Horizontal, bottom barriers.
- pointer_barriers_[1] = XFixesCreatePointerBarrier(
- xdisplay_, x_root_window_,
- bounds.x(), bounds.bottom(), bounds.right(), bounds.bottom(),
- BarrierNegativeY,
- 0, XIAllDevices);
- // Vertical, left barriers.
- pointer_barriers_[2] = XFixesCreatePointerBarrier(
- xdisplay_, x_root_window_,
- bounds.x(), bounds.y(), bounds.x(), bounds.bottom(),
- BarrierPositiveX,
- 0, XIAllDevices);
- // Vertical, right barriers.
- pointer_barriers_[3] = XFixesCreatePointerBarrier(
- xdisplay_, x_root_window_,
- bounds.right(), bounds.y(), bounds.right(), bounds.bottom(),
- BarrierNegativeX,
- 0, XIAllDevices);
-#endif
- return true;
-}
-
-void WindowTreeHostX11::UnConfineCursor() {
-#if XFIXES_MAJOR >= 5
- if (pointer_barriers_) {
- XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[0]);
- XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[1]);
- XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[2]);
- XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[3]);
- pointer_barriers_.reset();
- }
-#endif
-}
-
void WindowTreeHostX11::PostNativeEvent(
const base::NativeEvent& native_event) {
DCHECK(xwindow_);
@@ -717,25 +509,6 @@ void WindowTreeHostX11::MoveCursorToNative(const gfx::Point& location) {
}
void WindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) {
- SetCrOSTapPaused(!show);
-}
-
-void WindowTreeHostX11::OnWindowInitialized(Window* window) {
-}
-
-void WindowTreeHostX11::OnHostInitialized(WindowTreeHost* host) {
- // TODO(beng): I'm not sure that this comment makes much sense anymore??
- // UpdateIsInternalDisplay relies on WED's kDisplayIdKey property being set
- // available by the time WED::Init is called. (set in
- // DisplayManager::CreateRootWindowForDisplay)
- // Ready when NotifyHostInitialized is called from WED::Init.
- if (host != this)
- return;
- UpdateIsInternalDisplay();
-
- // We have to enable Tap-to-click by default because the cursor is set to
- // visible in Shell::InitRootWindowController.
- SetCrOSTapPaused(false);
}
ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() {
@@ -771,26 +544,11 @@ void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) {
// RootWindow will cause problem. So only generate the ui::TouchEvent
// when we are sure it belongs to this RootWindow.
if (base::SysInfo::IsRunningOnChromeOS() &&
- !bounds_.Contains(ui::EventLocationFromNative(xev)))
- break;
-#endif // defined(OS_CHROMEOS)
+ !bounds().Contains(ui::EventLocationFromNative(xev)))
+ return;
Yufeng Shen (Slow to review) 2014/04/09 21:35:51 Can we have a virtual bool WindowTreeHostX11::IsTo
oshima 2014/04/09 23:52:15 I was actually wondering why this needs to be cros
+#endif
ui::TouchEvent touchev(xev);
-#if defined(OS_CHROMEOS)
- 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)
- }
-#endif // defined(OS_CHROMEOS)
- SendEventToProcessor(&touchev);
+ TranslateAndDispatchLocatedEvent(&touchev);
break;
}
case ui::ET_MOUSE_MOVED:
@@ -807,12 +565,12 @@ void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) {
xev = &last_event;
}
ui::MouseEvent mouseev(xev);
- TranslateAndDispatchMouseEvent(&mouseev);
+ TranslateAndDispatchLocatedEvent(&mouseev);
break;
}
case ui::ET_MOUSEWHEEL: {
ui::MouseWheelEvent mouseev(xev);
- TranslateAndDispatchMouseEvent(&mouseev);
+ TranslateAndDispatchLocatedEvent(&mouseev);
break;
}
case ui::ET_SCROLL_FLING_START:
@@ -846,63 +604,11 @@ void WindowTreeHostX11::SetCursorInternal(gfx::NativeCursor cursor) {
XDefineCursor(xdisplay_, xwindow_, cursor.platform());
}
-void WindowTreeHostX11::TranslateAndDispatchMouseEvent(
- ui::MouseEvent* event) {
- Window* root_window = window();
- client::ScreenPositionClient* screen_position_client =
- client::GetScreenPositionClient(root_window);
- gfx::Rect local(bounds_.size());
-
- if (screen_position_client && !local.Contains(event->location())) {
- gfx::Point location(event->location());
- // In order to get the correct point in screen coordinates
- // during passive grab, we first need to find on which host window
- // the mouse is on, and find out the screen coordinates on that
- // host window, then convert it back to this host window's coordinate.
- screen_position_client->ConvertHostPointToScreen(root_window, &location);
- screen_position_client->ConvertPointFromScreen(root_window, &location);
- ConvertPointToHost(&location);
- event->set_location(location);
- event->set_root_location(location);
- }
- SendEventToProcessor(event);
-}
+void WindowTreeHostX11::OnConfigureNotify() {}
-void WindowTreeHostX11::UpdateIsInternalDisplay() {
- Window* root_window = window();
- gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window);
- gfx::Display display = screen->GetDisplayNearestWindow(root_window);
- is_internal_display_ = display.IsInternal();
-}
-
-void WindowTreeHostX11::SetCrOSTapPaused(bool state) {
-#if defined(OS_CHROMEOS)
- if (!ui::IsXInput2Available())
- return;
- // Temporarily pause tap-to-click when the cursor is hidden.
- Atom prop = atom_cache_.GetAtom("Tap Paused");
- unsigned char value = state;
- XIDeviceList dev_list =
- ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(xdisplay_);
-
- // Only slave pointer devices could possibly have tap-paused property.
- for (int i = 0; i < dev_list.count; i++) {
- if (dev_list[i].use == XISlavePointer) {
- Atom old_type;
- int old_format;
- unsigned long old_nvalues, bytes;
- unsigned char* data;
- int result = XIGetProperty(xdisplay_, dev_list[i].deviceid, prop, 0, 0,
- False, AnyPropertyType, &old_type, &old_format,
- &old_nvalues, &bytes, &data);
- if (result != Success)
- continue;
- XFree(data);
- XIChangeProperty(xdisplay_, dev_list[i].deviceid, prop, XA_INTEGER, 8,
- PropModeReplace, &value, 1);
- }
- }
-#endif
+void WindowTreeHostX11::TranslateAndDispatchLocatedEvent(
+ ui::LocatedEvent* event) {
+ SendEventToProcessor(event);
}
// static

Powered by Google App Engine
This is Rietveld 408576698