| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // DesktopWindowTreeHostX11, public: | 180 // DesktopWindowTreeHostX11, public: |
| 181 | 181 |
| 182 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( | 182 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( |
| 183 internal::NativeWidgetDelegate* native_widget_delegate, | 183 internal::NativeWidgetDelegate* native_widget_delegate, |
| 184 DesktopNativeWidgetAura* desktop_native_widget_aura) | 184 DesktopNativeWidgetAura* desktop_native_widget_aura) |
| 185 : xdisplay_(gfx::GetXDisplay()), | 185 : xdisplay_(gfx::GetXDisplay()), |
| 186 xwindow_(0), | 186 xwindow_(0), |
| 187 x_root_window_(DefaultRootWindow(xdisplay_)), | 187 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 188 atom_cache_(xdisplay_, kAtomsToCache), | 188 atom_cache_(xdisplay_, kAtomsToCache), |
| 189 window_mapped_(false), | 189 window_mapped_(false), |
| 190 wait_for_unmap_(false), | 190 is_visible_(false), |
| 191 is_fullscreen_(false), | 191 is_fullscreen_(false), |
| 192 is_always_on_top_(false), | 192 is_always_on_top_(false), |
| 193 use_native_frame_(false), | 193 use_native_frame_(false), |
| 194 should_maximize_after_map_(false), | 194 should_maximize_after_map_(false), |
| 195 use_argb_visual_(false), | 195 use_argb_visual_(false), |
| 196 drag_drop_client_(NULL), | 196 drag_drop_client_(NULL), |
| 197 native_widget_delegate_(native_widget_delegate), | 197 native_widget_delegate_(native_widget_delegate), |
| 198 desktop_native_widget_aura_(desktop_native_widget_aura), | 198 desktop_native_widget_aura_(desktop_native_widget_aura), |
| 199 content_window_(NULL), | 199 content_window_(NULL), |
| 200 window_parent_(NULL), | 200 window_parent_(NULL), |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 577 |
| 578 void DesktopWindowTreeHostX11::ShowMaximizedWithBounds( | 578 void DesktopWindowTreeHostX11::ShowMaximizedWithBounds( |
| 579 const gfx::Rect& restored_bounds) { | 579 const gfx::Rect& restored_bounds) { |
| 580 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); | 580 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); |
| 581 // Enforce |restored_bounds_in_pixels_| since calling Maximize() could have | 581 // Enforce |restored_bounds_in_pixels_| since calling Maximize() could have |
| 582 // reset it. | 582 // reset it. |
| 583 restored_bounds_in_pixels_ = ToPixelRect(restored_bounds); | 583 restored_bounds_in_pixels_ = ToPixelRect(restored_bounds); |
| 584 } | 584 } |
| 585 | 585 |
| 586 bool DesktopWindowTreeHostX11::IsVisible() const { | 586 bool DesktopWindowTreeHostX11::IsVisible() const { |
| 587 return window_mapped_ && !wait_for_unmap_; | 587 return is_visible_; |
| 588 } | 588 } |
| 589 | 589 |
| 590 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { | 590 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { |
| 591 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size(); | 591 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size(); |
| 592 size_in_pixels = AdjustSize(size_in_pixels); | 592 size_in_pixels = AdjustSize(size_in_pixels); |
| 593 bool size_changed = bounds_in_pixels_.size() != size_in_pixels; | 593 bool size_changed = bounds_in_pixels_.size() != size_in_pixels; |
| 594 XResizeWindow(xdisplay_, xwindow_, size_in_pixels.width(), | 594 XResizeWindow(xdisplay_, xwindow_, size_in_pixels.width(), |
| 595 size_in_pixels.height()); | 595 size_in_pixels.height()); |
| 596 bounds_in_pixels_.set_size(size_in_pixels); | 596 bounds_in_pixels_.set_size(size_in_pixels); |
| 597 if (size_changed) { | 597 if (size_changed) { |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 void DesktopWindowTreeHostX11::ShowImpl() { | 1193 void DesktopWindowTreeHostX11::ShowImpl() { |
| 1194 ShowWindowWithState(ui::SHOW_STATE_NORMAL); | 1194 ShowWindowWithState(ui::SHOW_STATE_NORMAL); |
| 1195 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); | 1195 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 void DesktopWindowTreeHostX11::HideImpl() { | 1198 void DesktopWindowTreeHostX11::HideImpl() { |
| 1199 if (IsVisible()) { | 1199 if (IsVisible()) { |
| 1200 XWithdrawWindow(xdisplay_, xwindow_, 0); | 1200 XWithdrawWindow(xdisplay_, xwindow_, 0); |
| 1201 wait_for_unmap_ = true; | 1201 is_visible_ = false; |
| 1202 } | 1202 } |
| 1203 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); | 1203 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); |
| 1204 } | 1204 } |
| 1205 | 1205 |
| 1206 gfx::Rect DesktopWindowTreeHostX11::GetBounds() const { | 1206 gfx::Rect DesktopWindowTreeHostX11::GetBounds() const { |
| 1207 return bounds_in_pixels_; | 1207 return bounds_in_pixels_; |
| 1208 } | 1208 } |
| 1209 | 1209 |
| 1210 void DesktopWindowTreeHostX11::SetBounds( | 1210 void DesktopWindowTreeHostX11::SetBounds( |
| 1211 const gfx::Rect& requested_bounds_in_pixel) { | 1211 const gfx::Rect& requested_bounds_in_pixel) { |
| 1212 gfx::Rect bounds_in_pixels(requested_bounds_in_pixel.origin(), | 1212 gfx::Rect bounds_in_pixels(requested_bounds_in_pixel.origin(), |
| 1213 AdjustSize(requested_bounds_in_pixel.size())); | 1213 AdjustSize(requested_bounds_in_pixel.size())); |
| 1214 bool origin_changed = bounds_in_pixels_.origin() != bounds_in_pixels.origin(); | 1214 bool origin_changed = bounds_in_pixels_.origin() != bounds_in_pixels.origin(); |
| 1215 bool size_changed = bounds_in_pixels_.size() != bounds_in_pixels.size(); | 1215 bool size_changed = bounds_in_pixels_.size() != bounds_in_pixels.size(); |
| 1216 XWindowChanges changes = {0}; | 1216 XWindowChanges changes = {0}; |
| 1217 unsigned value_mask = 0; | 1217 unsigned value_mask = 0; |
| 1218 | 1218 |
| 1219 delayed_resize_task_.Cancel(); | |
| 1220 | 1219 |
| 1221 if (size_changed) { | 1220 if (size_changed) { |
| 1221 // Only cancel the delayed resize task if we're already about to call |
| 1222 // OnHostResized in this function. |
| 1223 delayed_resize_task_.Cancel(); |
| 1224 |
| 1222 // Update the minimum and maximum sizes in case they have changed. | 1225 // Update the minimum and maximum sizes in case they have changed. |
| 1223 UpdateMinAndMaxSize(); | 1226 UpdateMinAndMaxSize(); |
| 1224 | 1227 |
| 1225 if (bounds_in_pixels.width() < min_size_in_pixels_.width() || | 1228 if (bounds_in_pixels.width() < min_size_in_pixels_.width() || |
| 1226 bounds_in_pixels.height() < min_size_in_pixels_.height() || | 1229 bounds_in_pixels.height() < min_size_in_pixels_.height() || |
| 1227 (!max_size_in_pixels_.IsEmpty() && | 1230 (!max_size_in_pixels_.IsEmpty() && |
| 1228 (bounds_in_pixels.width() > max_size_in_pixels_.width() || | 1231 (bounds_in_pixels.width() > max_size_in_pixels_.width() || |
| 1229 bounds_in_pixels.height() > max_size_in_pixels_.height()))) { | 1232 bounds_in_pixels.height() > max_size_in_pixels_.height()))) { |
| 1230 gfx::Size size_in_pixels = bounds_in_pixels.size(); | 1233 gfx::Size size_in_pixels = bounds_in_pixels.size(); |
| 1231 if (!max_size_in_pixels_.IsEmpty()) | 1234 if (!max_size_in_pixels_.IsEmpty()) |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 if (show_state == ui::SHOW_STATE_INACTIVE || wm_user_time_ms != 0) { | 1893 if (show_state == ui::SHOW_STATE_INACTIVE || wm_user_time_ms != 0) { |
| 1891 XChangeProperty( | 1894 XChangeProperty( |
| 1892 xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_USER_TIME"), | 1895 xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_USER_TIME"), |
| 1893 XA_CARDINAL, 32, PropModeReplace, | 1896 XA_CARDINAL, 32, PropModeReplace, |
| 1894 reinterpret_cast<const unsigned char*>(&wm_user_time_ms), 1); | 1897 reinterpret_cast<const unsigned char*>(&wm_user_time_ms), 1); |
| 1895 } | 1898 } |
| 1896 | 1899 |
| 1897 ui::X11EventSource* event_source = ui::X11EventSource::GetInstance(); | 1900 ui::X11EventSource* event_source = ui::X11EventSource::GetInstance(); |
| 1898 DCHECK(event_source); | 1901 DCHECK(event_source); |
| 1899 | 1902 |
| 1900 if (wait_for_unmap_) { | 1903 UpdateMinAndMaxSize(); |
| 1901 // Block until our window is unmapped. This avoids a race condition when | |
| 1902 // remapping an unmapped window. | |
| 1903 event_source->BlockUntilWindowUnmapped(xwindow_); | |
| 1904 DCHECK(!wait_for_unmap_); | |
| 1905 } | |
| 1906 | 1904 |
| 1907 XMapWindow(xdisplay_, xwindow_); | 1905 XMapWindow(xdisplay_, xwindow_); |
| 1908 | 1906 is_visible_ = true; |
| 1909 // We now block until our window is mapped. Some X11 APIs will crash and | |
| 1910 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | |
| 1911 // asynchronous. | |
| 1912 event_source->BlockUntilWindowMapped(xwindow_); | |
| 1913 } | 1907 } |
| 1914 | 1908 |
| 1915 void DesktopWindowTreeHostX11::SetWindowTransparency() { | 1909 void DesktopWindowTreeHostX11::SetWindowTransparency() { |
| 1916 compositor()->SetHostHasTransparentBackground(use_argb_visual_); | 1910 compositor()->SetHostHasTransparentBackground(use_argb_visual_); |
| 1917 window()->SetTransparent(use_argb_visual_); | 1911 window()->SetTransparent(use_argb_visual_); |
| 1918 content_window_->SetTransparent(use_argb_visual_); | 1912 content_window_->SetTransparent(use_argb_visual_); |
| 1919 } | 1913 } |
| 1920 | 1914 |
| 1921 void DesktopWindowTreeHostX11::Relayout() { | 1915 void DesktopWindowTreeHostX11::Relayout() { |
| 1922 Widget* widget = native_widget_delegate_->AsWidget(); | 1916 Widget* widget = native_widget_delegate_->AsWidget(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2131 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); | 2125 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); |
| 2132 break; | 2126 break; |
| 2133 } | 2127 } |
| 2134 case MapNotify: { | 2128 case MapNotify: { |
| 2135 window_mapped_ = true; | 2129 window_mapped_ = true; |
| 2136 | 2130 |
| 2137 FOR_EACH_OBSERVER(DesktopWindowTreeHostObserverX11, | 2131 FOR_EACH_OBSERVER(DesktopWindowTreeHostObserverX11, |
| 2138 observer_list_, | 2132 observer_list_, |
| 2139 OnWindowMapped(xwindow_)); | 2133 OnWindowMapped(xwindow_)); |
| 2140 | 2134 |
| 2141 UpdateMinAndMaxSize(); | |
| 2142 | |
| 2143 // Some WMs only respect maximize hints after the window has been mapped. | 2135 // Some WMs only respect maximize hints after the window has been mapped. |
| 2144 // Check whether we need to re-do a maximization. | 2136 // Check whether we need to re-do a maximization. |
| 2145 if (should_maximize_after_map_) { | 2137 if (should_maximize_after_map_) { |
| 2146 Maximize(); | 2138 Maximize(); |
| 2147 should_maximize_after_map_ = false; | 2139 should_maximize_after_map_ = false; |
| 2148 } | 2140 } |
| 2149 | 2141 |
| 2150 break; | 2142 break; |
| 2151 } | 2143 } |
| 2152 case UnmapNotify: { | 2144 case UnmapNotify: { |
| 2153 window_mapped_ = false; | 2145 window_mapped_ = false; |
| 2154 wait_for_unmap_ = false; | |
| 2155 has_pointer_ = false; | 2146 has_pointer_ = false; |
| 2156 has_pointer_grab_ = false; | 2147 has_pointer_grab_ = false; |
| 2157 has_pointer_focus_ = false; | 2148 has_pointer_focus_ = false; |
| 2158 has_window_focus_ = false; | 2149 has_window_focus_ = false; |
| 2159 FOR_EACH_OBSERVER(DesktopWindowTreeHostObserverX11, | 2150 FOR_EACH_OBSERVER(DesktopWindowTreeHostObserverX11, |
| 2160 observer_list_, | 2151 observer_list_, |
| 2161 OnWindowUnmapped(xwindow_)); | 2152 OnWindowUnmapped(xwindow_)); |
| 2162 break; | 2153 break; |
| 2163 } | 2154 } |
| 2164 case ClientMessage: { | 2155 case ClientMessage: { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2308 if (linux_ui) { | 2299 if (linux_ui) { |
| 2309 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 2300 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
| 2310 if (native_theme) | 2301 if (native_theme) |
| 2311 return native_theme; | 2302 return native_theme; |
| 2312 } | 2303 } |
| 2313 | 2304 |
| 2314 return ui::NativeThemeAura::instance(); | 2305 return ui::NativeThemeAura::instance(); |
| 2315 } | 2306 } |
| 2316 | 2307 |
| 2317 } // namespace views | 2308 } // namespace views |
| OLD | NEW |