OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_wayland.h" |
| 6 |
| 7 #include "ui/aura/client/focus_client.h" |
| 8 #include "ui/aura/window.h" |
| 9 #include "ui/aura/window_property.h" |
| 10 #include "ui/aura/window_tree_host.h" |
| 11 #include "ui/display/screen.h" |
| 12 #include "ui/native_theme/native_theme_aura.h" |
| 13 #include "ui/ozone/public/ozone_platform.h" |
| 14 #include "ui/views/corewm/tooltip_aura.h" |
| 15 #include "ui/views/linux_ui/linux_ui.h" |
| 16 #include "ui/views/views_delegate.h" |
| 17 #include "ui/views/views_export.h" |
| 18 #include "ui/views/views_switches.h" |
| 19 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_wayland.h" |
| 20 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 21 #include "ui/views/widget/desktop_aura/desktop_screen_wayland.h" |
| 22 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" |
| 23 #include "ui/wm/core/window_util.h" |
| 24 #include "ui/wm/public/window_move_client.h" |
| 25 |
| 26 namespace views { |
| 27 |
| 28 std::list<gfx::AcceleratedWidget>* |
| 29 DesktopWindowTreeHostWayland::open_windows_ = NULL; |
| 30 |
| 31 std::vector<aura::Window*>* |
| 32 DesktopWindowTreeHostWayland::aura_windows_ = NULL; |
| 33 |
| 34 DesktopWindowTreeHostWayland::DesktopWindowTreeHostWayland( |
| 35 internal::NativeWidgetDelegate* native_widget_delegate, |
| 36 DesktopNativeWidgetAura* desktop_native_widget_aura) |
| 37 : aura::WindowTreeHost(), |
| 38 state_(Uninitialized), |
| 39 window_(0), |
| 40 title_(base::string16()), |
| 41 drag_drop_client_(nullptr), |
| 42 native_widget_delegate_(native_widget_delegate), |
| 43 content_window_(nullptr), |
| 44 desktop_native_widget_aura_(desktop_native_widget_aura), |
| 45 window_parent_(nullptr), |
| 46 window_children_(), |
| 47 close_widget_factory_(this) { |
| 48 } |
| 49 |
| 50 DesktopWindowTreeHostWayland::~DesktopWindowTreeHostWayland() { |
| 51 aura::client::SetWindowMoveClient(window(), NULL); |
| 52 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); |
| 53 DestroyDispatcher(); |
| 54 } |
| 55 |
| 56 void DesktopWindowTreeHostWayland::CleanUpWindowList() { |
| 57 delete open_windows_; |
| 58 open_windows_ = NULL; |
| 59 if (aura_windows_) { |
| 60 aura_windows_->clear(); |
| 61 delete aura_windows_; |
| 62 aura_windows_ = NULL; |
| 63 } |
| 64 } |
| 65 |
| 66 gfx::Rect DesktopWindowTreeHostWayland::GetBoundsInScreen() const { |
| 67 return platform_window_->GetBounds(); |
| 68 } |
| 69 |
| 70 //////////////////////////////////////////////////////////////////////////////// |
| 71 // DesktopWindowTreeHostWayland, DesktopWindowTreeHost implementation: |
| 72 |
| 73 void DesktopWindowTreeHostWayland::Init( |
| 74 aura::Window* content_window, |
| 75 const Widget::InitParams& params) { |
| 76 content_window_ = content_window; |
| 77 // In some situations, views tries to make a zero sized window, and that |
| 78 // makes us crash. Make sure we have valid sizes. |
| 79 Widget::InitParams sanitized_params = params; |
| 80 if (sanitized_params.bounds.width() == 0) |
| 81 sanitized_params.bounds.set_width(100); |
| 82 if (sanitized_params.bounds.height() == 0) |
| 83 sanitized_params.bounds.set_height(100); |
| 84 |
| 85 platform_window_ = |
| 86 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, |
| 87 sanitized_params.bounds); |
| 88 DCHECK(window_); |
| 89 } |
| 90 |
| 91 void DesktopWindowTreeHostWayland::OnNativeWidgetCreated( |
| 92 const Widget::InitParams& params) { |
| 93 // If we're given a parent, we need to mark ourselves as transient to another |
| 94 // window. Otherwise activation gets screwy. |
| 95 gfx::NativeView parent = params.parent; |
| 96 if (!params.child && params.parent) |
| 97 wm::AddTransientChild(parent, content_window_); |
| 98 |
| 99 native_widget_delegate_->OnNativeWidgetCreated(true); |
| 100 open_windows().push_back(window_); |
| 101 if (aura_windows_) { |
| 102 aura_windows_->clear(); |
| 103 delete aura_windows_; |
| 104 aura_windows_ = NULL; |
| 105 } |
| 106 } |
| 107 |
| 108 std::unique_ptr<corewm::Tooltip> |
| 109 DesktopWindowTreeHostWayland::CreateTooltip() { |
| 110 return std::unique_ptr<views::corewm::Tooltip>( |
| 111 new views::corewm::TooltipAura); |
| 112 } |
| 113 |
| 114 std::unique_ptr<aura::client::DragDropClient> |
| 115 DesktopWindowTreeHostWayland::CreateDragDropClient( |
| 116 DesktopNativeCursorManager* cursor_manager) { |
| 117 //return base::WrapUnique(drag_drop_client_); |
| 118 return base::WrapUnique(drag_drop_client_); |
| 119 } |
| 120 |
| 121 |
| 122 void DesktopWindowTreeHostWayland::Close() { |
| 123 if (!close_widget_factory_.HasWeakPtrs()) { |
| 124 // And we delay the close so that if we are called from an ATL callback, |
| 125 // we don't destroy the window before the callback returned (as the caller |
| 126 // may delete ourselves on destroy and the ATL callback would still |
| 127 // dereference us when the callback returns). |
| 128 base::MessageLoop::current()->PostTask( |
| 129 FROM_HERE, |
| 130 base::Bind(&DesktopWindowTreeHostWayland::CloseNow, |
| 131 close_widget_factory_.GetWeakPtr())); |
| 132 } |
| 133 } |
| 134 |
| 135 void DesktopWindowTreeHostWayland::CloseNow() { |
| 136 if (!window_) |
| 137 return; |
| 138 |
| 139 unsigned widgetId = window_; |
| 140 ReleaseCapture(); |
| 141 native_widget_delegate_->OnNativeWidgetDestroying(); |
| 142 |
| 143 // If we have children, close them. Use a copy for iteration because they'll |
| 144 // remove themselves. |
| 145 std::set<DesktopWindowTreeHostWayland*> window_children_copy = |
| 146 window_children_; |
| 147 for (std::set<DesktopWindowTreeHostWayland*>::iterator it = |
| 148 window_children_copy.begin(); it != window_children_copy.end(); |
| 149 ++it) { |
| 150 (*it)->CloseNow(); |
| 151 } |
| 152 DCHECK(window_children_.empty()); |
| 153 |
| 154 // If we have a parent, remove ourselves from its children list. |
| 155 if (window_parent_) { |
| 156 window_parent_->window_children_.erase(this); |
| 157 window_parent_ = NULL; |
| 158 } |
| 159 |
| 160 // Destroy the compositor before destroying the window since shutdown |
| 161 // may try to swap, and the swap without a window causes an X error, which |
| 162 // causes a crash with in-process renderer. |
| 163 DestroyCompositor(); |
| 164 |
| 165 open_windows().remove(widgetId); |
| 166 if (aura_windows_) { |
| 167 aura_windows_->clear(); |
| 168 delete aura_windows_; |
| 169 aura_windows_ = NULL; |
| 170 } |
| 171 |
| 172 // Actually free our native resources. |
| 173 platform_window_->Close(); |
| 174 window_ = 0; |
| 175 if (open_windows().empty()) |
| 176 CleanUpWindowList(); |
| 177 |
| 178 desktop_native_widget_aura_->OnHostClosed(); |
| 179 } |
| 180 |
| 181 |
| 182 aura::WindowTreeHost* DesktopWindowTreeHostWayland::AsWindowTreeHost() { |
| 183 return this; |
| 184 } |
| 185 |
| 186 void DesktopWindowTreeHostWayland::ShowWindowWithState( |
| 187 ui::WindowShowState show_state) { |
| 188 if (compositor()) |
| 189 compositor()->SetVisible(true); |
| 190 state_ |= Visible; |
| 191 |
| 192 switch (show_state) { |
| 193 case ui::SHOW_STATE_NORMAL: |
| 194 Activate(); |
| 195 break; |
| 196 case ui::SHOW_STATE_MAXIMIZED: |
| 197 Maximize(); |
| 198 break; |
| 199 case ui::SHOW_STATE_MINIMIZED: |
| 200 Minimize(); |
| 201 break; |
| 202 case ui::SHOW_STATE_FULLSCREEN: |
| 203 break; |
| 204 default: |
| 205 break; |
| 206 } |
| 207 |
| 208 native_widget_delegate_->AsWidget()->SetInitialFocus(show_state); |
| 209 } |
| 210 |
| 211 void DesktopWindowTreeHostWayland::ShowMaximizedWithBounds( |
| 212 const gfx::Rect& restored_bounds) { |
| 213 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); |
| 214 previous_bounds_ = restored_bounds; |
| 215 } |
| 216 |
| 217 bool DesktopWindowTreeHostWayland::IsVisible() const { |
| 218 return state_ & Visible; |
| 219 } |
| 220 |
| 221 void DesktopWindowTreeHostWayland::SetSize(const gfx::Size& requested_size) { |
| 222 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size(); |
| 223 size_in_pixels = AdjustSize(size_in_pixels); |
| 224 gfx::Rect new_bounds = platform_window_->GetBounds(); |
| 225 new_bounds.set_size(size_in_pixels); |
| 226 platform_window_->SetBounds(new_bounds); |
| 227 } |
| 228 |
| 229 void DesktopWindowTreeHostWayland::StackAbove(aura::Window* window) { |
| 230 } |
| 231 |
| 232 void DesktopWindowTreeHostWayland::StackAtTop() { |
| 233 } |
| 234 |
| 235 void DesktopWindowTreeHostWayland::CenterWindow(const gfx::Size& size) { |
| 236 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(size)).size(); |
| 237 gfx::Rect parent_bounds_in_pixels = GetWorkAreaBoundsInScreen(); |
| 238 |
| 239 // If |window_|'s transient parent bounds are big enough to contain |size|, |
| 240 // use them instead. |
| 241 if (wm::GetTransientParent(content_window_)) { |
| 242 gfx::Rect transient_parent_rect = |
| 243 wm::GetTransientParent(content_window_)->GetBoundsInScreen(); |
| 244 if (transient_parent_rect.height() >= size.height() && |
| 245 transient_parent_rect.width() >= size.width()) { |
| 246 parent_bounds_in_pixels = ToPixelRect(transient_parent_rect); |
| 247 } |
| 248 } |
| 249 |
| 250 gfx::Rect window_bounds_in_pixels( |
| 251 parent_bounds_in_pixels.x() + |
| 252 (parent_bounds_in_pixels.width() - size_in_pixels.width()) / 2, |
| 253 parent_bounds_in_pixels.y() + |
| 254 (parent_bounds_in_pixels.height() - size_in_pixels.height()) / 2, |
| 255 size_in_pixels.width(), size_in_pixels.height()); |
| 256 // Don't size the window bigger than the parent, otherwise the user may not be |
| 257 // able to close or move it. |
| 258 window_bounds_in_pixels.AdjustToFit(parent_bounds_in_pixels); |
| 259 |
| 260 SetBounds(window_bounds_in_pixels); |
| 261 } |
| 262 |
| 263 void DesktopWindowTreeHostWayland::GetWindowPlacement( |
| 264 gfx::Rect* bounds, |
| 265 ui::WindowShowState* show_state) const { |
| 266 *bounds = GetRestoredBounds(); |
| 267 |
| 268 if (IsMinimized()) { |
| 269 *show_state = ui::SHOW_STATE_MINIMIZED; |
| 270 } else if (IsFullscreen()) { |
| 271 *show_state = ui::SHOW_STATE_FULLSCREEN; |
| 272 } else if (IsMaximized()) { |
| 273 *show_state = ui::SHOW_STATE_MAXIMIZED; |
| 274 } else if (!IsActive()) { |
| 275 *show_state = ui::SHOW_STATE_INACTIVE; |
| 276 } else { |
| 277 *show_state = ui::SHOW_STATE_NORMAL; |
| 278 } |
| 279 } |
| 280 |
| 281 gfx::Rect DesktopWindowTreeHostWayland::GetWindowBoundsInScreen() const { |
| 282 return platform_window_->GetBounds(); |
| 283 } |
| 284 |
| 285 gfx::Rect DesktopWindowTreeHostWayland::GetClientAreaBoundsInScreen() const { |
| 286 // TODO(erg): The NativeWidgetAura version returns |bounds_|, claiming its |
| 287 // needed for View::ConvertPointToScreen() to work |
| 288 // correctly. DesktopWindowTreeHostWin::GetClientAreaBoundsInScreen() just |
| 289 // asks windows what it thinks the client rect is. |
| 290 // |
| 291 // Attempts to calculate the rect by asking the NonClientFrameView what it |
| 292 // thought its GetBoundsForClientView() were broke combobox drop down |
| 293 // placement. |
| 294 return platform_window_->GetBounds(); |
| 295 } |
| 296 |
| 297 gfx::Rect DesktopWindowTreeHostWayland::GetRestoredBounds() const { |
| 298 if (!previous_bounds_.IsEmpty()) |
| 299 return ToDIPRect(previous_bounds_); |
| 300 |
| 301 return GetWindowBoundsInScreen(); |
| 302 } |
| 303 |
| 304 std::string DesktopWindowTreeHostWayland::GetWorkspace() const { |
| 305 return std::string(); |
| 306 } |
| 307 |
| 308 gfx::Rect DesktopWindowTreeHostWayland::GetWorkAreaBoundsInScreen() const { |
| 309 display::Screen *screen = display::Screen::GetScreen(); |
| 310 if (!screen) |
| 311 NOTREACHED() << "Unable to retrieve valid display::Screen"; |
| 312 |
| 313 display::Display display = screen->GetPrimaryDisplay(); |
| 314 return ToDIPRect(display.bounds()); |
| 315 } |
| 316 |
| 317 void DesktopWindowTreeHostWayland::SetShape(SkRegion* native_region) { |
| 318 // NOTIMPLEMENTED(); |
| 319 } |
| 320 |
| 321 void DesktopWindowTreeHostWayland::Activate() { |
| 322 if (state_ & Visible) { |
| 323 OnActivationChanged(true); |
| 324 } |
| 325 } |
| 326 |
| 327 void DesktopWindowTreeHostWayland::Deactivate() { |
| 328 OnActivationChanged(false); |
| 329 } |
| 330 |
| 331 bool DesktopWindowTreeHostWayland::IsActive() const { |
| 332 return state_ & Active; |
| 333 } |
| 334 |
| 335 void DesktopWindowTreeHostWayland::Maximize() { |
| 336 if (state_ & Maximized) |
| 337 return; |
| 338 |
| 339 state_ |= Maximized; |
| 340 state_ &= ~Minimized; |
| 341 previous_bounds_ = platform_window_->GetBounds(); |
| 342 platform_window_->Maximize(); |
| 343 if (IsMinimized()) |
| 344 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); |
| 345 } |
| 346 |
| 347 void DesktopWindowTreeHostWayland::Minimize() { |
| 348 if (state_ & Minimized) |
| 349 return; |
| 350 |
| 351 state_ |= Minimized; |
| 352 previous_bounds_ = platform_window_->GetBounds(); |
| 353 ReleaseCapture(); |
| 354 compositor()->SetVisible(false); |
| 355 content_window_->Hide(); |
| 356 platform_window_->Minimize(); |
| 357 Relayout(); |
| 358 } |
| 359 |
| 360 void DesktopWindowTreeHostWayland::Restore() { |
| 361 state_ &= ~Maximized; |
| 362 if (state_ & Minimized) { |
| 363 content_window_->Show(); |
| 364 compositor()->SetVisible(true); |
| 365 } |
| 366 |
| 367 platform_window_->Restore(); |
| 368 platform_window_->SetBounds(previous_bounds_); |
| 369 previous_bounds_ = gfx::Rect(); |
| 370 Relayout(); |
| 371 if (state_ & Minimized) { |
| 372 state_ &= ~Minimized; |
| 373 ShowWindow(); |
| 374 } |
| 375 } |
| 376 |
| 377 bool DesktopWindowTreeHostWayland::IsMaximized() const { |
| 378 return !IsFullscreen() && (state_ & Maximized); |
| 379 } |
| 380 |
| 381 bool DesktopWindowTreeHostWayland::IsMinimized() const { |
| 382 return state_ & Minimized; |
| 383 } |
| 384 |
| 385 bool DesktopWindowTreeHostWayland::HasCapture() const { |
| 386 return has_capture_; |
| 387 } |
| 388 |
| 389 |
| 390 void DesktopWindowTreeHostWayland::SetAlwaysOnTop(bool always_on_top) { |
| 391 always_on_top_ = always_on_top; |
| 392 } |
| 393 |
| 394 bool DesktopWindowTreeHostWayland::IsAlwaysOnTop() const { |
| 395 return always_on_top_; |
| 396 } |
| 397 |
| 398 void DesktopWindowTreeHostWayland::SetVisibleOnAllWorkspaces( |
| 399 bool always_visible) { |
| 400 NOTIMPLEMENTED(); |
| 401 } |
| 402 |
| 403 bool DesktopWindowTreeHostWayland::SetWindowTitle(const base::string16& title) { |
| 404 if (title.compare(title_)) { |
| 405 platform_window_->SetTitle(title); |
| 406 title_ = title; |
| 407 return true; |
| 408 } |
| 409 |
| 410 return false; |
| 411 } |
| 412 |
| 413 void DesktopWindowTreeHostWayland::ClearNativeFocus() { |
| 414 // This method is weird and misnamed. Instead of clearing the native focus, |
| 415 // it sets the focus to our |content_window_|, which will trigger a cascade |
| 416 // of focus changes into views. |
| 417 if (content_window_ && aura::client::GetFocusClient(content_window_) && |
| 418 content_window_->Contains( |
| 419 aura::client::GetFocusClient(content_window_)->GetFocusedWindow())) { |
| 420 aura::client::GetFocusClient(content_window_)->FocusWindow(content_window_); |
| 421 } |
| 422 } |
| 423 |
| 424 Widget::MoveLoopResult DesktopWindowTreeHostWayland::RunMoveLoop( |
| 425 const gfx::Vector2d& drag_offset, |
| 426 Widget::MoveLoopSource source, |
| 427 Widget::MoveLoopEscapeBehavior escape_behavior) { |
| 428 NOTIMPLEMENTED(); |
| 429 return Widget::MOVE_LOOP_SUCCESSFUL; |
| 430 } |
| 431 |
| 432 |
| 433 void DesktopWindowTreeHostWayland::EndMoveLoop() { |
| 434 NOTIMPLEMENTED(); |
| 435 } |
| 436 |
| 437 void DesktopWindowTreeHostWayland::SetVisibilityChangedAnimationsEnabled( |
| 438 bool value) { |
| 439 // Much like the previous NativeWidgetGtk, we don't have anything to do here. |
| 440 } |
| 441 |
| 442 bool DesktopWindowTreeHostWayland::ShouldUseNativeFrame() const { |
| 443 return false; |
| 444 } |
| 445 |
| 446 bool DesktopWindowTreeHostWayland::ShouldWindowContentsBeTransparent() const { |
| 447 return false; |
| 448 } |
| 449 |
| 450 void DesktopWindowTreeHostWayland::FrameTypeChanged() { |
| 451 Widget::FrameType new_type = |
| 452 native_widget_delegate_->AsWidget()->frame_type(); |
| 453 if (new_type == Widget::FRAME_TYPE_DEFAULT) { |
| 454 // The default is determined by Widget::InitParams::remove_standard_frame |
| 455 // and does not change. |
| 456 return; |
| 457 } |
| 458 |
| 459 // Replace the frame and layout the contents. Even though we don't have a |
| 460 // swapable glass frame like on Windows, we still replace the frame because |
| 461 // the button assets don't update otherwise. |
| 462 native_widget_delegate_->AsWidget()->non_client_view()->UpdateFrame(); |
| 463 } |
| 464 |
| 465 void DesktopWindowTreeHostWayland::SetFullscreen(bool fullscreen) { |
| 466 NOTIMPLEMENTED(); |
| 467 } |
| 468 |
| 469 bool DesktopWindowTreeHostWayland::IsFullscreen() const { |
| 470 return state_ & FullScreen; |
| 471 } |
| 472 |
| 473 void DesktopWindowTreeHostWayland::SetOpacity(float opacity) { |
| 474 content_window_->layer()->SetOpacity(opacity / 255.0); |
| 475 } |
| 476 |
| 477 void DesktopWindowTreeHostWayland::SetWindowIcons( |
| 478 const gfx::ImageSkia& window_icon, const gfx::ImageSkia& app_icon) { |
| 479 NOTIMPLEMENTED(); |
| 480 } |
| 481 |
| 482 void DesktopWindowTreeHostWayland::InitModalType(ui::ModalType modal_type) { |
| 483 switch (modal_type) { |
| 484 case ui::MODAL_TYPE_NONE: |
| 485 break; |
| 486 default: |
| 487 // TODO(erg): Figure out under what situations |modal_type| isn't |
| 488 // none. The comment in desktop_native_widget_aura.cc suggests that this |
| 489 // is rare. |
| 490 NOTIMPLEMENTED(); |
| 491 } |
| 492 } |
| 493 |
| 494 void DesktopWindowTreeHostWayland::FlashFrame(bool flash_frame) { |
| 495 NOTIMPLEMENTED(); |
| 496 } |
| 497 |
| 498 void DesktopWindowTreeHostWayland::OnRootViewLayout() { |
| 499 } |
| 500 |
| 501 void DesktopWindowTreeHostWayland::OnNativeWidgetFocus() { |
| 502 } |
| 503 |
| 504 void DesktopWindowTreeHostWayland::OnNativeWidgetBlur() { |
| 505 } |
| 506 |
| 507 bool DesktopWindowTreeHostWayland::IsAnimatingClosed() const { |
| 508 return false; |
| 509 } |
| 510 |
| 511 bool DesktopWindowTreeHostWayland::IsTranslucentWindowOpacitySupported() const { |
| 512 return false; |
| 513 } |
| 514 |
| 515 void DesktopWindowTreeHostWayland::SizeConstraintsChanged() { |
| 516 } |
| 517 |
| 518 //////////////////////////////////////////////////////////////////////////////// |
| 519 // DesktopWindowTreeHostWayland, aura::WindowTreeHost implementation: |
| 520 |
| 521 gfx::Transform DesktopWindowTreeHostWayland::GetRootTransform() const { |
| 522 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 523 aura::Window* win = const_cast<aura::Window*>(window()); |
| 524 display = display::Screen::GetScreen()->GetDisplayNearestWindow(win); |
| 525 |
| 526 float scale = display.device_scale_factor(); |
| 527 gfx::Transform transform; |
| 528 transform.Scale(scale, scale); |
| 529 return transform; |
| 530 } |
| 531 |
| 532 ui::EventSource* DesktopWindowTreeHostWayland::GetEventSource() { |
| 533 return this; |
| 534 } |
| 535 |
| 536 gfx::AcceleratedWidget DesktopWindowTreeHostWayland::GetAcceleratedWidget() { |
| 537 return window_; |
| 538 } |
| 539 |
| 540 void DesktopWindowTreeHostWayland::ShowImpl() { |
| 541 if (state_ & Visible) |
| 542 return; |
| 543 |
| 544 ShowWindowWithState(ui::SHOW_STATE_NORMAL); |
| 545 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); |
| 546 } |
| 547 |
| 548 void DesktopWindowTreeHostWayland::HideImpl() { |
| 549 if (!(state_ & Visible)) |
| 550 return; |
| 551 |
| 552 state_ &= ~Visible; |
| 553 platform_window_->Hide(); |
| 554 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); |
| 555 } |
| 556 |
| 557 gfx::Rect DesktopWindowTreeHostWayland::GetBounds() const { |
| 558 return platform_window_->GetBounds(); |
| 559 } |
| 560 |
| 561 void DesktopWindowTreeHostWayland::SetBounds( |
| 562 const gfx::Rect& requested_bounds) { |
| 563 gfx::Rect bounds(requested_bounds.origin(), |
| 564 AdjustSize(requested_bounds.size())); |
| 565 platform_window_->SetBounds(bounds); |
| 566 } |
| 567 |
| 568 gfx::Point DesktopWindowTreeHostWayland::GetLocationOnNativeScreen() const { |
| 569 return platform_window_->GetBounds().origin(); |
| 570 } |
| 571 |
| 572 void DesktopWindowTreeHostWayland::SetCapture() { |
| 573 if (has_capture_) |
| 574 return; |
| 575 |
| 576 has_capture_ = true; |
| 577 platform_window_->SetCapture(); |
| 578 } |
| 579 |
| 580 void DesktopWindowTreeHostWayland::ReleaseCapture() { |
| 581 platform_window_->ReleaseCapture(); |
| 582 OnLostCapture(); |
| 583 } |
| 584 |
| 585 void DesktopWindowTreeHostWayland::ShowWindow() { |
| 586 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; |
| 587 if (IsMinimized()) { |
| 588 show_state = ui::SHOW_STATE_MINIMIZED; |
| 589 } else if (IsFullscreen()) { |
| 590 show_state = ui::SHOW_STATE_FULLSCREEN; |
| 591 } else if (IsMaximized()) { |
| 592 show_state = ui::SHOW_STATE_MAXIMIZED; |
| 593 } else if (!IsActive()) { |
| 594 show_state = ui::SHOW_STATE_INACTIVE; |
| 595 } |
| 596 |
| 597 ShowWindowWithState(show_state); |
| 598 } |
| 599 |
| 600 void DesktopWindowTreeHostWayland::SetCursorNative(gfx::NativeCursor cursor) { |
| 601 platform_window_->SetCursor(cursor.platform()); |
| 602 } |
| 603 |
| 604 void DesktopWindowTreeHostWayland::MoveCursorToNative( |
| 605 const gfx::Point& location) { |
| 606 platform_window_->MoveCursorTo(location); |
| 607 } |
| 608 |
| 609 void DesktopWindowTreeHostWayland::OnCursorVisibilityChangedNative(bool show) { |
| 610 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do |
| 611 // the same tap-to-click disabling here that chromeos does. |
| 612 } |
| 613 |
| 614 //////////////////////////////////////////////////////////////////////////////// |
| 615 // ui::PlatformWindowDelegate implementation: |
| 616 void DesktopWindowTreeHostWayland::OnBoundsChanged( |
| 617 const gfx::Rect& new_bounds) { |
| 618 |
| 619 native_widget_delegate_->AsWidget()->OnNativeWidgetMove(); |
| 620 OnHostResized(new_bounds.size()); |
| 621 ResetWindowRegion(); |
| 622 } |
| 623 |
| 624 void DesktopWindowTreeHostWayland::OnDamageRect(const gfx::Rect& damaged_rect) { |
| 625 compositor()->ScheduleRedrawRect(damaged_rect); |
| 626 } |
| 627 |
| 628 void DesktopWindowTreeHostWayland::OnAcceleratedWidgetDestroyed() { |
| 629 gfx::AcceleratedWidget window = compositor()->ReleaseAcceleratedWidget(); |
| 630 DCHECK_EQ(window, window_); |
| 631 window_ = gfx::kNullAcceleratedWidget; |
| 632 } |
| 633 |
| 634 void DesktopWindowTreeHostWayland::OnActivationChanged(bool active) { |
| 635 if (active == (state_ & Active)) |
| 636 return; |
| 637 |
| 638 if (active) { |
| 639 // Make sure the stacking order is correct. The activated window should be |
| 640 // first one in list of open windows. |
| 641 std::list<gfx::AcceleratedWidget>& windows = open_windows(); |
| 642 DCHECK(windows.size()); |
| 643 if (windows.front() != window_) { |
| 644 windows.remove(window_); |
| 645 windows.insert(windows.begin(), window_); |
| 646 } |
| 647 |
| 648 state_ |= Active; |
| 649 OnHostActivated(); |
| 650 } else { |
| 651 state_ &= ~Active; |
| 652 ReleaseCapture(); |
| 653 } |
| 654 |
| 655 desktop_native_widget_aura_->HandleActivationChanged(active); |
| 656 native_widget_delegate_->AsWidget()->GetRootView()->SchedulePaint(); |
| 657 } |
| 658 |
| 659 |
| 660 void DesktopWindowTreeHostWayland::OnLostCapture() { |
| 661 OnHostLostWindowCapture(); |
| 662 has_capture_ = false; |
| 663 } |
| 664 |
| 665 void DesktopWindowTreeHostWayland::OnAcceleratedWidgetAvailable( |
| 666 gfx::AcceleratedWidget widget, |
| 667 float device_pixel_ratio) { |
| 668 window_ = widget; |
| 669 CreateCompositor(); |
| 670 WindowTreeHost::OnAcceleratedWidgetAvailable(); |
| 671 } |
| 672 |
| 673 void DesktopWindowTreeHostWayland::OnCloseRequest() { |
| 674 Close(); |
| 675 } |
| 676 |
| 677 void DesktopWindowTreeHostWayland::OnClosed() { |
| 678 CloseNow(); |
| 679 } |
| 680 |
| 681 void DesktopWindowTreeHostWayland::OnWindowStateChanged( |
| 682 ui::PlatformWindowState new_state) { |
| 683 |
| 684 switch (new_state) { |
| 685 case ui::PLATFORM_WINDOW_STATE_MAXIMIZED: { |
| 686 if (state_ & Minimized) { |
| 687 content_window_->Show(); |
| 688 compositor()->SetVisible(true); |
| 689 state_ &= ~Minimized; |
| 690 } |
| 691 platform_window_->SetBounds(previous_bounds_); |
| 692 previous_bounds_ = gfx::Rect(); |
| 693 Relayout(); |
| 694 break; |
| 695 } |
| 696 default: |
| 697 break; |
| 698 } |
| 699 } |
| 700 |
| 701 void DesktopWindowTreeHostWayland::DispatchEvent(ui::Event* event) { |
| 702 SendEventToProcessor(event); |
| 703 } |
| 704 |
| 705 //////////////////////////////////////////////////////////////////////////////// |
| 706 // DesktopWindowTreeHostWayland, private: |
| 707 |
| 708 void DesktopWindowTreeHostWayland::Relayout() { |
| 709 Widget* widget = native_widget_delegate_->AsWidget(); |
| 710 NonClientView* non_client_view = widget->non_client_view(); |
| 711 // non_client_view may be NULL, especially during creation. |
| 712 if (non_client_view) { |
| 713 non_client_view->client_view()->InvalidateLayout(); |
| 714 non_client_view->InvalidateLayout(); |
| 715 } |
| 716 widget->GetRootView()->Layout(); |
| 717 ResetWindowRegion(); |
| 718 } |
| 719 |
| 720 std::list<gfx::AcceleratedWidget>& |
| 721 DesktopWindowTreeHostWayland::open_windows() { |
| 722 if (!open_windows_) |
| 723 open_windows_ = new std::list<gfx::AcceleratedWidget>(); |
| 724 return *open_windows_; |
| 725 } |
| 726 |
| 727 gfx::Size DesktopWindowTreeHostWayland::AdjustSize( |
| 728 const gfx::Size& requested_size_in_pixels) { |
| 729 |
| 730 std::vector<display::Display> displays = |
| 731 display::Screen::GetScreen()->GetAllDisplays(); |
| 732 // Compare against all monitor sizes. The window manager can move the window |
| 733 // to whichever monitor it wants. |
| 734 for (size_t i = 0; i < displays.size(); ++i) { |
| 735 if (requested_size_in_pixels == displays[i].GetSizeInPixel()) { |
| 736 return gfx::Size(requested_size_in_pixels.width() - 1, |
| 737 requested_size_in_pixels.height() - 1); |
| 738 } |
| 739 } |
| 740 |
| 741 // Do not request a 0x0 window size. |
| 742 gfx::Size size_in_pixels = requested_size_in_pixels; |
| 743 size_in_pixels.SetToMax(gfx::Size(1, 1)); |
| 744 return size_in_pixels; |
| 745 } |
| 746 |
| 747 gfx::Rect DesktopWindowTreeHostWayland::ToDIPRect( |
| 748 const gfx::Rect& rect_in_pixels) const { |
| 749 gfx::RectF rect_in_dip = gfx::RectF(rect_in_pixels); |
| 750 GetRootTransform().TransformRectReverse(&rect_in_dip); |
| 751 return gfx::ToEnclosingRect(rect_in_dip); |
| 752 } |
| 753 |
| 754 gfx::Rect DesktopWindowTreeHostWayland::ToPixelRect( |
| 755 const gfx::Rect& rect_in_dip) const { |
| 756 gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip); |
| 757 GetRootTransform().TransformRect(&rect_in_pixels); |
| 758 return gfx::ToEnclosingRect(rect_in_pixels); |
| 759 } |
| 760 |
| 761 void DesktopWindowTreeHostWayland::ResetWindowRegion() { |
| 762 if (custom_window_shape_) |
| 763 return; |
| 764 |
| 765 gfx::Path window_mask; |
| 766 const gfx::Rect& bounds_in_pixels = platform_window_->GetBounds(); |
| 767 if (!IsMaximized() && !IsFullscreen()) { |
| 768 views::Widget* widget = native_widget_delegate_->AsWidget(); |
| 769 if (widget->non_client_view()) { |
| 770 // Some frame views define a custom (non-rectangular) window mask. If |
| 771 // so, use it to define the window shape. If not, fall through. |
| 772 widget->non_client_view()->GetWindowMask(bounds_in_pixels.size(), |
| 773 &window_mask); |
| 774 } |
| 775 } |
| 776 } |
| 777 |
| 778 } // namespace views |
OLD | NEW |