| OLD | NEW |
| 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 "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 6 | 6 |
| 7 #include <X11/extensions/shape.h> | 7 #include <X11/extensions/shape.h> |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
| 10 #include <X11/Xregion.h> | 10 #include <X11/Xregion.h> |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 } | 593 } |
| 594 | 594 |
| 595 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { | 595 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { |
| 596 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size(); | 596 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size(); |
| 597 size_in_pixels = AdjustSize(size_in_pixels); | 597 size_in_pixels = AdjustSize(size_in_pixels); |
| 598 bool size_changed = bounds_in_pixels_.size() != size_in_pixels; | 598 bool size_changed = bounds_in_pixels_.size() != size_in_pixels; |
| 599 XResizeWindow(xdisplay_, xwindow_, size_in_pixels.width(), | 599 XResizeWindow(xdisplay_, xwindow_, size_in_pixels.width(), |
| 600 size_in_pixels.height()); | 600 size_in_pixels.height()); |
| 601 bounds_in_pixels_.set_size(size_in_pixels); | 601 bounds_in_pixels_.set_size(size_in_pixels); |
| 602 if (size_changed) { | 602 if (size_changed) { |
| 603 OnHostResized(size_in_pixels); | 603 OnHostResizedInPixel(size_in_pixels); |
| 604 ResetWindowRegion(); | 604 ResetWindowRegion(); |
| 605 } | 605 } |
| 606 } | 606 } |
| 607 | 607 |
| 608 void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) { | 608 void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) { |
| 609 if (window && window->GetRootWindow()) { | 609 if (window && window->GetRootWindow()) { |
| 610 ::Window window_below = window->GetHost()->GetAcceleratedWidget(); | 610 ::Window window_below = window->GetHost()->GetAcceleratedWidget(); |
| 611 // Find all parent windows up to the root. | 611 // Find all parent windows up to the root. |
| 612 std::vector<::Window> window_below_parents = | 612 std::vector<::Window> window_below_parents = |
| 613 GetParentsList(xdisplay_, window_below); | 613 GetParentsList(xdisplay_, window_below); |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 // synchronously. | 1061 // synchronously. |
| 1062 // See https://crbug.com/361408 | 1062 // See https://crbug.com/361408 |
| 1063 if (fullscreen) { | 1063 if (fullscreen) { |
| 1064 restored_bounds_in_pixels_ = bounds_in_pixels_; | 1064 restored_bounds_in_pixels_ = bounds_in_pixels_; |
| 1065 const display::Display display = | 1065 const display::Display display = |
| 1066 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); | 1066 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); |
| 1067 bounds_in_pixels_ = ToPixelRect(display.bounds()); | 1067 bounds_in_pixels_ = ToPixelRect(display.bounds()); |
| 1068 } else { | 1068 } else { |
| 1069 bounds_in_pixels_ = restored_bounds_in_pixels_; | 1069 bounds_in_pixels_ = restored_bounds_in_pixels_; |
| 1070 } | 1070 } |
| 1071 OnHostMoved(bounds_in_pixels_.origin()); | 1071 OnHostMovedInPixel(bounds_in_pixels_.origin()); |
| 1072 OnHostResized(bounds_in_pixels_.size()); | 1072 OnHostResizedInPixel(bounds_in_pixels_.size()); |
| 1073 | 1073 |
| 1074 if (HasWMSpecProperty("_NET_WM_STATE_FULLSCREEN") == fullscreen) { | 1074 if (HasWMSpecProperty("_NET_WM_STATE_FULLSCREEN") == fullscreen) { |
| 1075 Relayout(); | 1075 Relayout(); |
| 1076 ResetWindowRegion(); | 1076 ResetWindowRegion(); |
| 1077 } | 1077 } |
| 1078 // Else: the widget will be relaid out either when the window bounds change or | 1078 // Else: the widget will be relaid out either when the window bounds change or |
| 1079 // when |xwindow_|'s fullscreen state changes. | 1079 // when |xwindow_|'s fullscreen state changes. |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 bool DesktopWindowTreeHostX11::IsFullscreen() const { | 1082 bool DesktopWindowTreeHostX11::IsFullscreen() const { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 // Assume that the resize will go through as requested, which should be the | 1251 // Assume that the resize will go through as requested, which should be the |
| 1252 // case if we're running without a window manager. If there's a window | 1252 // case if we're running without a window manager. If there's a window |
| 1253 // manager, it can modify or ignore the request, but (per ICCCM) we'll get a | 1253 // manager, it can modify or ignore the request, but (per ICCCM) we'll get a |
| 1254 // (possibly synthetic) ConfigureNotify about the actual size and correct | 1254 // (possibly synthetic) ConfigureNotify about the actual size and correct |
| 1255 // |bounds_in_pixels_| later. | 1255 // |bounds_in_pixels_| later. |
| 1256 bounds_in_pixels_ = bounds_in_pixels; | 1256 bounds_in_pixels_ = bounds_in_pixels; |
| 1257 | 1257 |
| 1258 if (origin_changed) | 1258 if (origin_changed) |
| 1259 native_widget_delegate_->AsWidget()->OnNativeWidgetMove(); | 1259 native_widget_delegate_->AsWidget()->OnNativeWidgetMove(); |
| 1260 if (size_changed) { | 1260 if (size_changed) { |
| 1261 OnHostResized(bounds_in_pixels.size()); | 1261 OnHostResizedInPixel(bounds_in_pixels.size()); |
| 1262 ResetWindowRegion(); | 1262 ResetWindowRegion(); |
| 1263 } | 1263 } |
| 1264 } | 1264 } |
| 1265 | 1265 |
| 1266 gfx::Point DesktopWindowTreeHostX11::GetLocationOnNativeScreen() const { | 1266 gfx::Point DesktopWindowTreeHostX11::GetLocationOnNativeScreenInPixel() const { |
| 1267 return bounds_in_pixels_.origin(); | 1267 return bounds_in_pixels_.origin(); |
| 1268 } | 1268 } |
| 1269 | 1269 |
| 1270 void DesktopWindowTreeHostX11::SetCapture() { | 1270 void DesktopWindowTreeHostX11::SetCapture() { |
| 1271 if (HasCapture()) | 1271 if (HasCapture()) |
| 1272 return; | 1272 return; |
| 1273 | 1273 |
| 1274 // Grabbing the mouse is asynchronous. However, we synchronously start | 1274 // Grabbing the mouse is asynchronous. However, we synchronously start |
| 1275 // forwarding all mouse events received by Chrome to the | 1275 // forwarding all mouse events received by Chrome to the |
| 1276 // aura::WindowEventDispatcher which has capture. This makes capture | 1276 // aura::WindowEventDispatcher which has capture. This makes capture |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1301 has_pointer_grab_ = false; | 1301 has_pointer_grab_ = false; |
| 1302 | 1302 |
| 1303 OnHostLostWindowCapture(); | 1303 OnHostLostWindowCapture(); |
| 1304 } | 1304 } |
| 1305 } | 1305 } |
| 1306 | 1306 |
| 1307 void DesktopWindowTreeHostX11::SetCursorNative(gfx::NativeCursor cursor) { | 1307 void DesktopWindowTreeHostX11::SetCursorNative(gfx::NativeCursor cursor) { |
| 1308 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); | 1308 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); |
| 1309 } | 1309 } |
| 1310 | 1310 |
| 1311 void DesktopWindowTreeHostX11::MoveCursorToNative(const gfx::Point& location) { | 1311 void DesktopWindowTreeHostX11::MoveCursorToNativeInPixel( |
| 1312 const gfx::Point& location_in_pixel) { |
| 1312 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, | 1313 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, |
| 1313 bounds_in_pixels_.x() + location.x(), | 1314 bounds_in_pixels_.x() + location_in_pixel.x(), |
| 1314 bounds_in_pixels_.y() + location.y()); | 1315 bounds_in_pixels_.y() + location_in_pixel.y()); |
| 1315 } | 1316 } |
| 1316 | 1317 |
| 1317 void DesktopWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { | 1318 void DesktopWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { |
| 1318 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do | 1319 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do |
| 1319 // the same tap-to-click disabling here that chromeos does. | 1320 // the same tap-to-click disabling here that chromeos does. |
| 1320 } | 1321 } |
| 1321 | 1322 |
| 1322 //////////////////////////////////////////////////////////////////////////////// | 1323 //////////////////////////////////////////////////////////////////////////////// |
| 1323 // DesktopWindowTreeHostX11, private: | 1324 // DesktopWindowTreeHostX11, private: |
| 1324 | 1325 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 bool was_minimized = IsMinimized(); | 1570 bool was_minimized = IsMinimized(); |
| 1570 | 1571 |
| 1571 window_properties_.clear(); | 1572 window_properties_.clear(); |
| 1572 std::copy(atom_list.begin(), atom_list.end(), | 1573 std::copy(atom_list.begin(), atom_list.end(), |
| 1573 inserter(window_properties_, window_properties_.begin())); | 1574 inserter(window_properties_, window_properties_.begin())); |
| 1574 | 1575 |
| 1575 // Propagate the window minimization information to the content window, so | 1576 // Propagate the window minimization information to the content window, so |
| 1576 // the render side can update its visibility properly. OnWMStateUpdated() is | 1577 // the render side can update its visibility properly. OnWMStateUpdated() is |
| 1577 // called by PropertyNofify event from DispatchEvent() when the browser is | 1578 // called by PropertyNofify event from DispatchEvent() when the browser is |
| 1578 // minimized or shown from minimized state. On Windows, this is realized by | 1579 // minimized or shown from minimized state. On Windows, this is realized by |
| 1579 // calling OnHostResized() with an empty size. In particular, | 1580 // calling OnHostResizedInPixel() with an empty size. In particular, |
| 1580 // HWNDMessageHandler::GetClientAreaBounds() returns an empty size when the | 1581 // HWNDMessageHandler::GetClientAreaBounds() returns an empty size when the |
| 1581 // window is minimized. On Linux, returning empty size in GetBounds() or | 1582 // window is minimized. On Linux, returning empty size in GetBounds() or |
| 1582 // SetBounds() does not work. | 1583 // SetBounds() does not work. |
| 1583 // We also propagate the minimization to the compositor, to makes sure that we | 1584 // We also propagate the minimization to the compositor, to makes sure that we |
| 1584 // don't draw any 'blank' frames that could be noticed in applications such as | 1585 // don't draw any 'blank' frames that could be noticed in applications such as |
| 1585 // window manager previews, which show content even when a window is | 1586 // window manager previews, which show content even when a window is |
| 1586 // minimized. | 1587 // minimized. |
| 1587 bool is_minimized = IsMinimized(); | 1588 bool is_minimized = IsMinimized(); |
| 1588 if (is_minimized != was_minimized) { | 1589 if (is_minimized != was_minimized) { |
| 1589 if (is_minimized) { | 1590 if (is_minimized) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 void DesktopWindowTreeHostX11::ConvertEventToDifferentHost( | 1789 void DesktopWindowTreeHostX11::ConvertEventToDifferentHost( |
| 1789 ui::LocatedEvent* located_event, | 1790 ui::LocatedEvent* located_event, |
| 1790 DesktopWindowTreeHostX11* host) { | 1791 DesktopWindowTreeHostX11* host) { |
| 1791 DCHECK_NE(this, host); | 1792 DCHECK_NE(this, host); |
| 1792 const display::Display display_src = | 1793 const display::Display display_src = |
| 1793 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); | 1794 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); |
| 1794 const display::Display display_dest = | 1795 const display::Display display_dest = |
| 1795 display::Screen::GetScreen()->GetDisplayNearestWindow(host->window()); | 1796 display::Screen::GetScreen()->GetDisplayNearestWindow(host->window()); |
| 1796 DCHECK_EQ(display_src.device_scale_factor(), | 1797 DCHECK_EQ(display_src.device_scale_factor(), |
| 1797 display_dest.device_scale_factor()); | 1798 display_dest.device_scale_factor()); |
| 1798 gfx::Vector2d offset = GetLocationOnNativeScreen() - | 1799 gfx::Vector2d offset = GetLocationOnNativeScreenInPixel() - |
| 1799 host->GetLocationOnNativeScreen(); | 1800 host->GetLocationOnNativeScreenInPixel(); |
| 1800 gfx::PointF location_in_pixel_in_host = | 1801 gfx::PointF location_in_pixel_in_host = |
| 1801 located_event->location_f() + gfx::Vector2dF(offset); | 1802 located_event->location_f() + gfx::Vector2dF(offset); |
| 1802 located_event->set_location_f(location_in_pixel_in_host); | 1803 located_event->set_location_f(location_in_pixel_in_host); |
| 1803 located_event->set_root_location_f(location_in_pixel_in_host); | 1804 located_event->set_root_location_f(location_in_pixel_in_host); |
| 1804 } | 1805 } |
| 1805 | 1806 |
| 1806 void DesktopWindowTreeHostX11::ResetWindowRegion() { | 1807 void DesktopWindowTreeHostX11::ResetWindowRegion() { |
| 1807 // If a custom window shape was supplied then apply it. | 1808 // If a custom window shape was supplied then apply it. |
| 1808 if (custom_window_shape_) { | 1809 if (custom_window_shape_) { |
| 1809 XShapeCombineRegion(xdisplay_, xwindow_, ShapeBounding, 0, 0, | 1810 XShapeCombineRegion(xdisplay_, xwindow_, ShapeBounding, 0, 0, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2043 } | 2044 } |
| 2044 gfx::Rect bounds_in_pixels(translated_x_in_pixels, translated_y_in_pixels, | 2045 gfx::Rect bounds_in_pixels(translated_x_in_pixels, translated_y_in_pixels, |
| 2045 xev->xconfigure.width, xev->xconfigure.height); | 2046 xev->xconfigure.width, xev->xconfigure.height); |
| 2046 bool size_changed = bounds_in_pixels_.size() != bounds_in_pixels.size(); | 2047 bool size_changed = bounds_in_pixels_.size() != bounds_in_pixels.size(); |
| 2047 bool origin_changed = | 2048 bool origin_changed = |
| 2048 bounds_in_pixels_.origin() != bounds_in_pixels.origin(); | 2049 bounds_in_pixels_.origin() != bounds_in_pixels.origin(); |
| 2049 previous_bounds_in_pixels_ = bounds_in_pixels_; | 2050 previous_bounds_in_pixels_ = bounds_in_pixels_; |
| 2050 bounds_in_pixels_ = bounds_in_pixels; | 2051 bounds_in_pixels_ = bounds_in_pixels; |
| 2051 | 2052 |
| 2052 if (origin_changed) | 2053 if (origin_changed) |
| 2053 OnHostMoved(bounds_in_pixels_.origin()); | 2054 OnHostMovedInPixel(bounds_in_pixels_.origin()); |
| 2054 | 2055 |
| 2055 if (size_changed) { | 2056 if (size_changed) { |
| 2056 delayed_resize_task_.Reset(base::Bind( | 2057 delayed_resize_task_.Reset(base::Bind( |
| 2057 &DesktopWindowTreeHostX11::DelayedResize, | 2058 &DesktopWindowTreeHostX11::DelayedResize, |
| 2058 close_widget_factory_.GetWeakPtr(), bounds_in_pixels.size())); | 2059 close_widget_factory_.GetWeakPtr(), bounds_in_pixels.size())); |
| 2059 base::ThreadTaskRunnerHandle::Get()->PostTask( | 2060 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2060 FROM_HERE, delayed_resize_task_.callback()); | 2061 FROM_HERE, delayed_resize_task_.callback()); |
| 2061 } | 2062 } |
| 2062 break; | 2063 break; |
| 2063 } | 2064 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2256 } | 2257 } |
| 2257 case SelectionNotify: { | 2258 case SelectionNotify: { |
| 2258 drag_drop_client_->OnSelectionNotify(xev->xselection); | 2259 drag_drop_client_->OnSelectionNotify(xev->xselection); |
| 2259 break; | 2260 break; |
| 2260 } | 2261 } |
| 2261 } | 2262 } |
| 2262 return ui::POST_DISPATCH_STOP_PROPAGATION; | 2263 return ui::POST_DISPATCH_STOP_PROPAGATION; |
| 2263 } | 2264 } |
| 2264 | 2265 |
| 2265 void DesktopWindowTreeHostX11::DelayedResize(const gfx::Size& size_in_pixels) { | 2266 void DesktopWindowTreeHostX11::DelayedResize(const gfx::Size& size_in_pixels) { |
| 2266 OnHostResized(size_in_pixels); | 2267 OnHostResizedInPixel(size_in_pixels); |
| 2267 ResetWindowRegion(); | 2268 ResetWindowRegion(); |
| 2268 delayed_resize_task_.Cancel(); | 2269 delayed_resize_task_.Cancel(); |
| 2269 } | 2270 } |
| 2270 | 2271 |
| 2271 gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInPixels() const { | 2272 gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInPixels() const { |
| 2272 std::vector<int> value; | 2273 std::vector<int> value; |
| 2273 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && | 2274 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && |
| 2274 value.size() >= 4) { | 2275 value.size() >= 4) { |
| 2275 return gfx::Rect(value[0], value[1], value[2], value[3]); | 2276 return gfx::Rect(value[0], value[1], value[2], value[3]); |
| 2276 } | 2277 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2345 if (linux_ui) { | 2346 if (linux_ui) { |
| 2346 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 2347 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
| 2347 if (native_theme) | 2348 if (native_theme) |
| 2348 return native_theme; | 2349 return native_theme; |
| 2349 } | 2350 } |
| 2350 | 2351 |
| 2351 return ui::NativeThemeAura::instance(); | 2352 return ui::NativeThemeAura::instance(); |
| 2352 } | 2353 } |
| 2353 | 2354 |
| 2354 } // namespace views | 2355 } // namespace views |
| OLD | NEW |