| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 is_fullscreen_(false), | 144 is_fullscreen_(false), |
| 145 is_always_on_top_(false), | 145 is_always_on_top_(false), |
| 146 use_native_frame_(false), | 146 use_native_frame_(false), |
| 147 should_maximize_after_map_(false), | 147 should_maximize_after_map_(false), |
| 148 use_argb_visual_(false), | 148 use_argb_visual_(false), |
| 149 drag_drop_client_(NULL), | 149 drag_drop_client_(NULL), |
| 150 native_widget_delegate_(native_widget_delegate), | 150 native_widget_delegate_(native_widget_delegate), |
| 151 desktop_native_widget_aura_(desktop_native_widget_aura), | 151 desktop_native_widget_aura_(desktop_native_widget_aura), |
| 152 content_window_(NULL), | 152 content_window_(NULL), |
| 153 window_parent_(NULL), | 153 window_parent_(NULL), |
| 154 window_shape_(NULL), | |
| 155 custom_window_shape_(false), | 154 custom_window_shape_(false), |
| 156 urgency_hint_set_(false), | 155 urgency_hint_set_(false), |
| 157 close_widget_factory_(this) { | 156 close_widget_factory_(this) { |
| 158 } | 157 } |
| 159 | 158 |
| 160 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { | 159 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { |
| 161 window()->ClearProperty(kHostForRootWindow); | 160 window()->ClearProperty(kHostForRootWindow); |
| 162 aura::client::SetWindowMoveClient(window(), NULL); | 161 aura::client::SetWindowMoveClient(window(), NULL); |
| 163 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); | 162 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); |
| 164 if (window_shape_) | |
| 165 XDestroyRegion(window_shape_); | |
| 166 DestroyDispatcher(); | 163 DestroyDispatcher(); |
| 167 } | 164 } |
| 168 | 165 |
| 169 // static | 166 // static |
| 170 aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) { | 167 aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) { |
| 171 aura::WindowTreeHost* host = | 168 aura::WindowTreeHost* host = |
| 172 aura::WindowTreeHost::GetForAcceleratedWidget(xid); | 169 aura::WindowTreeHost::GetForAcceleratedWidget(xid); |
| 173 return host ? host->window()->GetProperty(kViewsWindowForRootWindow) : NULL; | 170 return host ? host->window()->GetProperty(kViewsWindowForRootWindow) : NULL; |
| 174 } | 171 } |
| 175 | 172 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 194 return bounds_in_pixels_; | 191 return bounds_in_pixels_; |
| 195 } | 192 } |
| 196 | 193 |
| 197 gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowOuterBounds() const { | 194 gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowOuterBounds() const { |
| 198 gfx::Rect outer_bounds(bounds_in_pixels_); | 195 gfx::Rect outer_bounds(bounds_in_pixels_); |
| 199 outer_bounds.Inset(-native_window_frame_borders_in_pixels_); | 196 outer_bounds.Inset(-native_window_frame_borders_in_pixels_); |
| 200 return outer_bounds; | 197 return outer_bounds; |
| 201 } | 198 } |
| 202 | 199 |
| 203 ::Region DesktopWindowTreeHostX11::GetWindowShape() const { | 200 ::Region DesktopWindowTreeHostX11::GetWindowShape() const { |
| 204 return window_shape_; | 201 return window_shape_.get(); |
| 205 } | 202 } |
| 206 | 203 |
| 207 void DesktopWindowTreeHostX11::HandleNativeWidgetActivationChanged( | 204 void DesktopWindowTreeHostX11::HandleNativeWidgetActivationChanged( |
| 208 bool active) { | 205 bool active) { |
| 209 if (active) { | 206 if (active) { |
| 210 FlashFrame(false); | 207 FlashFrame(false); |
| 211 OnHostActivated(); | 208 OnHostActivated(); |
| 212 open_windows().remove(xwindow_); | 209 open_windows().remove(xwindow_); |
| 213 open_windows().insert(open_windows().begin(), xwindow_); | 210 open_windows().insert(open_windows().begin(), xwindow_); |
| 214 } else { | 211 } else { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 return ToDIPRect(restored_bounds_in_pixels_); | 476 return ToDIPRect(restored_bounds_in_pixels_); |
| 480 | 477 |
| 481 return GetWindowBoundsInScreen(); | 478 return GetWindowBoundsInScreen(); |
| 482 } | 479 } |
| 483 | 480 |
| 484 gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInScreen() const { | 481 gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInScreen() const { |
| 485 return ToDIPRect(GetWorkAreaBoundsInPixels()); | 482 return ToDIPRect(GetWorkAreaBoundsInPixels()); |
| 486 } | 483 } |
| 487 | 484 |
| 488 void DesktopWindowTreeHostX11::SetShape(gfx::NativeRegion native_region) { | 485 void DesktopWindowTreeHostX11::SetShape(gfx::NativeRegion native_region) { |
| 489 if (window_shape_) | |
| 490 XDestroyRegion(window_shape_); | |
| 491 custom_window_shape_ = false; | 486 custom_window_shape_ = false; |
| 492 window_shape_ = NULL; | 487 window_shape_.reset(); |
| 493 | 488 |
| 494 if (native_region) { | 489 if (native_region) { |
| 495 gfx::Transform transform = GetRootTransform(); | 490 gfx::Transform transform = GetRootTransform(); |
| 496 if (!transform.IsIdentity() && !native_region->isEmpty()) { | 491 if (!transform.IsIdentity() && !native_region->isEmpty()) { |
| 497 SkPath path_in_dip; | 492 SkPath path_in_dip; |
| 498 if (native_region->getBoundaryPath(&path_in_dip)) { | 493 if (native_region->getBoundaryPath(&path_in_dip)) { |
| 499 SkPath path_in_pixels; | 494 SkPath path_in_pixels; |
| 500 path_in_dip.transform(transform.matrix(), &path_in_pixels); | 495 path_in_dip.transform(transform.matrix(), &path_in_pixels); |
| 501 window_shape_ = gfx::CreateRegionFromSkPath(path_in_pixels); | 496 window_shape_.reset(gfx::CreateRegionFromSkPath(path_in_pixels)); |
| 502 } else { | 497 } else { |
| 503 window_shape_ = XCreateRegion(); | 498 window_shape_.reset(XCreateRegion()); |
| 504 } | 499 } |
| 505 } else { | 500 } else { |
| 506 window_shape_ = gfx::CreateRegionFromSkRegion(*native_region); | 501 window_shape_.reset(gfx::CreateRegionFromSkRegion(*native_region)); |
| 507 } | 502 } |
| 508 | 503 |
| 509 custom_window_shape_ = true; | 504 custom_window_shape_ = true; |
| 510 delete native_region; | 505 delete native_region; |
| 511 } | 506 } |
| 512 ResetWindowRegion(); | 507 ResetWindowRegion(); |
| 513 } | 508 } |
| 514 | 509 |
| 515 void DesktopWindowTreeHostX11::Activate() { | 510 void DesktopWindowTreeHostX11::Activate() { |
| 516 if (!window_mapped_) | 511 if (!window_mapped_) |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 display_dest.device_scale_factor()); | 1466 display_dest.device_scale_factor()); |
| 1472 gfx::Vector2d offset = GetLocationOnNativeScreen() - | 1467 gfx::Vector2d offset = GetLocationOnNativeScreen() - |
| 1473 host->GetLocationOnNativeScreen(); | 1468 host->GetLocationOnNativeScreen(); |
| 1474 gfx::Point location_in_pixel_in_host = located_event->location() + offset; | 1469 gfx::Point location_in_pixel_in_host = located_event->location() + offset; |
| 1475 located_event->set_location(location_in_pixel_in_host); | 1470 located_event->set_location(location_in_pixel_in_host); |
| 1476 } | 1471 } |
| 1477 | 1472 |
| 1478 void DesktopWindowTreeHostX11::ResetWindowRegion() { | 1473 void DesktopWindowTreeHostX11::ResetWindowRegion() { |
| 1479 // If a custom window shape was supplied then apply it. | 1474 // If a custom window shape was supplied then apply it. |
| 1480 if (custom_window_shape_) { | 1475 if (custom_window_shape_) { |
| 1481 XShapeCombineRegion( | 1476 XShapeCombineRegion(xdisplay_, xwindow_, ShapeBounding, 0, 0, |
| 1482 xdisplay_, xwindow_, ShapeBounding, 0, 0, window_shape_, false); | 1477 window_shape_.get(), false); |
| 1483 return; | 1478 return; |
| 1484 } | 1479 } |
| 1485 | 1480 |
| 1486 if (window_shape_) | 1481 window_shape_.reset(); |
| 1487 XDestroyRegion(window_shape_); | |
| 1488 window_shape_ = NULL; | |
| 1489 | 1482 |
| 1490 if (!IsMaximized() && !IsFullscreen()) { | 1483 if (!IsMaximized() && !IsFullscreen()) { |
| 1491 gfx::Path window_mask; | 1484 gfx::Path window_mask; |
| 1492 views::Widget* widget = native_widget_delegate_->AsWidget(); | 1485 views::Widget* widget = native_widget_delegate_->AsWidget(); |
| 1493 if (widget->non_client_view()) { | 1486 if (widget->non_client_view()) { |
| 1494 // Some frame views define a custom (non-rectangular) window mask. If | 1487 // Some frame views define a custom (non-rectangular) window mask. If |
| 1495 // so, use it to define the window shape. If not, fall through. | 1488 // so, use it to define the window shape. If not, fall through. |
| 1496 widget->non_client_view()->GetWindowMask(bounds_in_pixels_.size(), | 1489 widget->non_client_view()->GetWindowMask(bounds_in_pixels_.size(), |
| 1497 &window_mask); | 1490 &window_mask); |
| 1498 if (window_mask.countPoints() > 0) { | 1491 if (window_mask.countPoints() > 0) { |
| 1499 window_shape_ = gfx::CreateRegionFromSkPath(window_mask); | 1492 window_shape_.reset(gfx::CreateRegionFromSkPath(window_mask)); |
| 1500 XShapeCombineRegion(xdisplay_, xwindow_, ShapeBounding, | 1493 XShapeCombineRegion(xdisplay_, xwindow_, ShapeBounding, 0, 0, |
| 1501 0, 0, window_shape_, false); | 1494 window_shape_.get(), false); |
| 1502 return; | 1495 return; |
| 1503 } | 1496 } |
| 1504 } | 1497 } |
| 1505 } | 1498 } |
| 1506 | 1499 |
| 1507 // If we didn't set the shape for any reason, reset the shaping information. | 1500 // If we didn't set the shape for any reason, reset the shaping information. |
| 1508 // How this is done depends on the border style, due to quirks and bugs in | 1501 // How this is done depends on the border style, due to quirks and bugs in |
| 1509 // various window managers. | 1502 // various window managers. |
| 1510 if (ShouldUseNativeFrame()) { | 1503 if (ShouldUseNativeFrame()) { |
| 1511 // If the window has system borders, the mask must be set to null (not a | 1504 // If the window has system borders, the mask must be set to null (not a |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 if (linux_ui) { | 1985 if (linux_ui) { |
| 1993 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 1986 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
| 1994 if (native_theme) | 1987 if (native_theme) |
| 1995 return native_theme; | 1988 return native_theme; |
| 1996 } | 1989 } |
| 1997 | 1990 |
| 1998 return ui::NativeTheme::instance(); | 1991 return ui::NativeTheme::instance(); |
| 1999 } | 1992 } |
| 2000 | 1993 |
| 2001 } // namespace views | 1994 } // namespace views |
| OLD | NEW |