Chromium Code Reviews| 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_map_(false), | |
| 190 wait_for_unmap_(false), | 191 wait_for_unmap_(false), |
| 191 is_fullscreen_(false), | 192 is_fullscreen_(false), |
| 192 is_always_on_top_(false), | 193 is_always_on_top_(false), |
| 193 use_native_frame_(false), | 194 use_native_frame_(false), |
| 194 should_maximize_after_map_(false), | 195 should_maximize_after_map_(false), |
| 195 use_argb_visual_(false), | 196 use_argb_visual_(false), |
| 196 drag_drop_client_(NULL), | 197 drag_drop_client_(NULL), |
| 197 native_widget_delegate_(native_widget_delegate), | 198 native_widget_delegate_(native_widget_delegate), |
| 198 desktop_native_widget_aura_(desktop_native_widget_aura), | 199 desktop_native_widget_aura_(desktop_native_widget_aura), |
| 199 content_window_(NULL), | 200 content_window_(NULL), |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 | 578 |
| 578 void DesktopWindowTreeHostX11::ShowMaximizedWithBounds( | 579 void DesktopWindowTreeHostX11::ShowMaximizedWithBounds( |
| 579 const gfx::Rect& restored_bounds) { | 580 const gfx::Rect& restored_bounds) { |
| 580 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); | 581 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); |
| 581 // Enforce |restored_bounds_in_pixels_| since calling Maximize() could have | 582 // Enforce |restored_bounds_in_pixels_| since calling Maximize() could have |
| 582 // reset it. | 583 // reset it. |
| 583 restored_bounds_in_pixels_ = ToPixelRect(restored_bounds); | 584 restored_bounds_in_pixels_ = ToPixelRect(restored_bounds); |
| 584 } | 585 } |
| 585 | 586 |
| 586 bool DesktopWindowTreeHostX11::IsVisible() const { | 587 bool DesktopWindowTreeHostX11::IsVisible() const { |
| 587 return window_mapped_ && !wait_for_unmap_; | 588 return wait_for_map_ || (window_mapped_ && !wait_for_unmap_); |
| 588 } | 589 } |
| 589 | 590 |
| 590 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { | 591 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { |
| 591 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size(); | 592 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size(); |
| 592 size_in_pixels = AdjustSize(size_in_pixels); | 593 size_in_pixels = AdjustSize(size_in_pixels); |
| 593 bool size_changed = bounds_in_pixels_.size() != size_in_pixels; | 594 bool size_changed = bounds_in_pixels_.size() != size_in_pixels; |
| 594 XResizeWindow(xdisplay_, xwindow_, size_in_pixels.width(), | 595 XResizeWindow(xdisplay_, xwindow_, size_in_pixels.width(), |
| 595 size_in_pixels.height()); | 596 size_in_pixels.height()); |
| 596 bounds_in_pixels_.set_size(size_in_pixels); | 597 bounds_in_pixels_.set_size(size_in_pixels); |
| 597 if (size_changed) { | 598 if (size_changed) { |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1192 | 1193 |
| 1193 void DesktopWindowTreeHostX11::ShowImpl() { | 1194 void DesktopWindowTreeHostX11::ShowImpl() { |
| 1194 ShowWindowWithState(ui::SHOW_STATE_NORMAL); | 1195 ShowWindowWithState(ui::SHOW_STATE_NORMAL); |
| 1195 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); | 1196 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); |
| 1196 } | 1197 } |
| 1197 | 1198 |
| 1198 void DesktopWindowTreeHostX11::HideImpl() { | 1199 void DesktopWindowTreeHostX11::HideImpl() { |
| 1199 if (IsVisible()) { | 1200 if (IsVisible()) { |
| 1200 XWithdrawWindow(xdisplay_, xwindow_, 0); | 1201 XWithdrawWindow(xdisplay_, xwindow_, 0); |
| 1201 wait_for_unmap_ = true; | 1202 wait_for_unmap_ = true; |
| 1203 wait_for_map_ = false; | |
| 1202 } | 1204 } |
| 1203 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); | 1205 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); |
| 1204 } | 1206 } |
| 1205 | 1207 |
| 1206 gfx::Rect DesktopWindowTreeHostX11::GetBounds() const { | 1208 gfx::Rect DesktopWindowTreeHostX11::GetBounds() const { |
| 1207 return bounds_in_pixels_; | 1209 return bounds_in_pixels_; |
| 1208 } | 1210 } |
| 1209 | 1211 |
| 1210 void DesktopWindowTreeHostX11::SetBounds( | 1212 void DesktopWindowTreeHostX11::SetBounds( |
| 1211 const gfx::Rect& requested_bounds_in_pixel) { | 1213 const gfx::Rect& requested_bounds_in_pixel) { |
| 1212 gfx::Rect bounds_in_pixels(requested_bounds_in_pixel.origin(), | 1214 gfx::Rect bounds_in_pixels(requested_bounds_in_pixel.origin(), |
| 1213 AdjustSize(requested_bounds_in_pixel.size())); | 1215 AdjustSize(requested_bounds_in_pixel.size())); |
| 1214 bool origin_changed = bounds_in_pixels_.origin() != bounds_in_pixels.origin(); | 1216 bool origin_changed = bounds_in_pixels_.origin() != bounds_in_pixels.origin(); |
| 1215 bool size_changed = bounds_in_pixels_.size() != bounds_in_pixels.size(); | 1217 bool size_changed = bounds_in_pixels_.size() != bounds_in_pixels.size(); |
| 1216 XWindowChanges changes = {0}; | 1218 XWindowChanges changes = {0}; |
| 1217 unsigned value_mask = 0; | 1219 unsigned value_mask = 0; |
| 1218 | 1220 |
| 1219 delayed_resize_task_.Cancel(); | |
| 1220 | 1221 |
| 1221 if (size_changed) { | 1222 if (size_changed) { |
| 1223 // Only cancel the delayed resize task if we're already about to call | |
| 1224 // OnHostResized in this function. | |
| 1225 delayed_resize_task_.Cancel(); | |
| 1226 | |
| 1222 // Update the minimum and maximum sizes in case they have changed. | 1227 // Update the minimum and maximum sizes in case they have changed. |
| 1223 UpdateMinAndMaxSize(); | 1228 UpdateMinAndMaxSize(); |
| 1224 | 1229 |
| 1225 if (bounds_in_pixels.width() < min_size_in_pixels_.width() || | 1230 if (bounds_in_pixels.width() < min_size_in_pixels_.width() || |
| 1226 bounds_in_pixels.height() < min_size_in_pixels_.height() || | 1231 bounds_in_pixels.height() < min_size_in_pixels_.height() || |
| 1227 (!max_size_in_pixels_.IsEmpty() && | 1232 (!max_size_in_pixels_.IsEmpty() && |
| 1228 (bounds_in_pixels.width() > max_size_in_pixels_.width() || | 1233 (bounds_in_pixels.width() > max_size_in_pixels_.width() || |
| 1229 bounds_in_pixels.height() > max_size_in_pixels_.height()))) { | 1234 bounds_in_pixels.height() > max_size_in_pixels_.height()))) { |
| 1230 gfx::Size size_in_pixels = bounds_in_pixels.size(); | 1235 gfx::Size size_in_pixels = bounds_in_pixels.size(); |
| 1231 if (!max_size_in_pixels_.IsEmpty()) | 1236 if (!max_size_in_pixels_.IsEmpty()) |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1891 XChangeProperty( | 1896 XChangeProperty( |
| 1892 xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_USER_TIME"), | 1897 xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_USER_TIME"), |
| 1893 XA_CARDINAL, 32, PropModeReplace, | 1898 XA_CARDINAL, 32, PropModeReplace, |
| 1894 reinterpret_cast<const unsigned char*>(&wm_user_time_ms), 1); | 1899 reinterpret_cast<const unsigned char*>(&wm_user_time_ms), 1); |
| 1895 } | 1900 } |
| 1896 | 1901 |
| 1897 ui::X11EventSource* event_source = ui::X11EventSource::GetInstance(); | 1902 ui::X11EventSource* event_source = ui::X11EventSource::GetInstance(); |
| 1898 DCHECK(event_source); | 1903 DCHECK(event_source); |
| 1899 | 1904 |
| 1900 if (wait_for_unmap_) { | 1905 if (wait_for_unmap_) { |
| 1901 // Block until our window is unmapped. This avoids a race condition when | 1906 // Block until our window is unmapped. This avoids a race condition when |
|
Tom (Use chromium acct)
2016/09/12 22:45:07
We don't need lines 1900 to 1905 any more now that
dackerman
2016/09/23 14:12:37
I didn't remove this since I don't know in what sc
Tom (Use chromium acct)
2016/09/23 18:35:48
This code was only recently added to fix the probl
dackerman
2016/09/25 19:45:36
Done.
| |
| 1902 // remapping an unmapped window. | 1907 // remapping an unmapped window. |
| 1903 event_source->BlockUntilWindowUnmapped(xwindow_); | 1908 event_source->BlockUntilWindowUnmapped(xwindow_); |
| 1904 DCHECK(!wait_for_unmap_); | 1909 DCHECK(!wait_for_unmap_); |
| 1905 } | 1910 } |
| 1906 | 1911 |
| 1907 XMapWindow(xdisplay_, xwindow_); | 1912 XMapWindow(xdisplay_, xwindow_); |
| 1908 | 1913 wait_for_map_ = 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 } | 1914 } |
| 1914 | 1915 |
| 1915 void DesktopWindowTreeHostX11::SetWindowTransparency() { | 1916 void DesktopWindowTreeHostX11::SetWindowTransparency() { |
| 1916 compositor()->SetHostHasTransparentBackground(use_argb_visual_); | 1917 compositor()->SetHostHasTransparentBackground(use_argb_visual_); |
| 1917 window()->SetTransparent(use_argb_visual_); | 1918 window()->SetTransparent(use_argb_visual_); |
| 1918 content_window_->SetTransparent(use_argb_visual_); | 1919 content_window_->SetTransparent(use_argb_visual_); |
| 1919 } | 1920 } |
| 1920 | 1921 |
| 1921 void DesktopWindowTreeHostX11::Relayout() { | 1922 void DesktopWindowTreeHostX11::Relayout() { |
| 1922 Widget* widget = native_widget_delegate_->AsWidget(); | 1923 Widget* widget = native_widget_delegate_->AsWidget(); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2125 default: | 2126 default: |
| 2126 NOTREACHED(); | 2127 NOTREACHED(); |
| 2127 } | 2128 } |
| 2128 | 2129 |
| 2129 // If we coalesced an event we need to free its cookie. | 2130 // If we coalesced an event we need to free its cookie. |
| 2130 if (num_coalesced > 0) | 2131 if (num_coalesced > 0) |
| 2131 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); | 2132 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); |
| 2132 break; | 2133 break; |
| 2133 } | 2134 } |
| 2134 case MapNotify: { | 2135 case MapNotify: { |
| 2136 wait_for_map_ = false; | |
| 2135 window_mapped_ = true; | 2137 window_mapped_ = true; |
| 2136 | 2138 |
| 2137 FOR_EACH_OBSERVER(DesktopWindowTreeHostObserverX11, | 2139 FOR_EACH_OBSERVER(DesktopWindowTreeHostObserverX11, |
| 2138 observer_list_, | 2140 observer_list_, |
| 2139 OnWindowMapped(xwindow_)); | 2141 OnWindowMapped(xwindow_)); |
| 2140 | 2142 |
| 2141 UpdateMinAndMaxSize(); | 2143 UpdateMinAndMaxSize(); |
| 2142 | 2144 |
| 2143 // Some WMs only respect maximize hints after the window has been mapped. | 2145 // Some WMs only respect maximize hints after the window has been mapped. |
| 2144 // Check whether we need to re-do a maximization. | 2146 // Check whether we need to re-do a maximization. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2308 if (linux_ui) { | 2310 if (linux_ui) { |
| 2309 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 2311 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
| 2310 if (native_theme) | 2312 if (native_theme) |
| 2311 return native_theme; | 2313 return native_theme; |
| 2312 } | 2314 } |
| 2313 | 2315 |
| 2314 return ui::NativeThemeAura::instance(); | 2316 return ui::NativeThemeAura::instance(); |
| 2315 } | 2317 } |
| 2316 | 2318 |
| 2317 } // namespace views | 2319 } // namespace views |
| OLD | NEW |