| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/mus/desktop_window_tree_host_mus.h" | 5 #include "ui/views/mus/desktop_window_tree_host_mus.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
| 10 #include "ui/aura/client/drag_drop_client.h" | 10 #include "ui/aura/client/drag_drop_client.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ui/views/widget/widget_delegate.h" | 24 #include "ui/views/widget/widget_delegate.h" |
| 25 #include "ui/wm/core/cursor_manager.h" | 25 #include "ui/wm/core/cursor_manager.h" |
| 26 #include "ui/wm/core/native_cursor_manager.h" | 26 #include "ui/wm/core/native_cursor_manager.h" |
| 27 #include "ui/wm/core/window_util.h" | 27 #include "ui/wm/core/window_util.h" |
| 28 #include "ui/wm/public/activation_client.h" | 28 #include "ui/wm/public/activation_client.h" |
| 29 | 29 |
| 30 namespace views { | 30 namespace views { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 bool ShouldSetClientArea(views::Widget::InitParams::Type type) { | |
| 35 using WIP = views::Widget::InitParams; | |
| 36 return type == WIP::TYPE_WINDOW || type == WIP::TYPE_PANEL; | |
| 37 } | |
| 38 | |
| 39 // As the window manager renderers the non-client decorations this class does | 34 // As the window manager renderers the non-client decorations this class does |
| 40 // very little but honor the client area insets from the window manager. | 35 // very little but honor the client area insets from the window manager. |
| 41 class ClientSideNonClientFrameView : public NonClientFrameView { | 36 class ClientSideNonClientFrameView : public NonClientFrameView { |
| 42 public: | 37 public: |
| 43 explicit ClientSideNonClientFrameView(views::Widget* widget) | 38 explicit ClientSideNonClientFrameView(views::Widget* widget) |
| 44 : widget_(widget) {} | 39 : widget_(widget) {} |
| 45 ~ClientSideNonClientFrameView() override {} | 40 ~ClientSideNonClientFrameView() override {} |
| 46 | 41 |
| 47 private: | 42 private: |
| 48 // Returns the default values of client area insets from the window manager. | 43 // Returns the default values of client area insets from the window manager. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 aura::Env::GetInstance()->RemoveObserver(this); | 189 aura::Env::GetInstance()->RemoveObserver(this); |
| 195 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); | 190 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); |
| 196 } | 191 } |
| 197 | 192 |
| 198 bool DesktopWindowTreeHostMus::IsDocked() const { | 193 bool DesktopWindowTreeHostMus::IsDocked() const { |
| 199 return window()->GetProperty(aura::client::kShowStateKey) == | 194 return window()->GetProperty(aura::client::kShowStateKey) == |
| 200 ui::SHOW_STATE_DOCKED; | 195 ui::SHOW_STATE_DOCKED; |
| 201 } | 196 } |
| 202 | 197 |
| 203 void DesktopWindowTreeHostMus::SendClientAreaToServer() { | 198 void DesktopWindowTreeHostMus::SendClientAreaToServer() { |
| 204 if (!ShouldSetClientArea(desktop_native_widget_aura_->widget_type())) | 199 if (!ShouldSendClientAreaToServer()) |
| 205 return; | 200 return; |
| 206 | 201 |
| 207 NonClientView* non_client_view = | 202 NonClientView* non_client_view = |
| 208 native_widget_delegate_->AsWidget()->non_client_view(); | 203 native_widget_delegate_->AsWidget()->non_client_view(); |
| 209 if (!non_client_view || !non_client_view->client_view()) | 204 if (!non_client_view || !non_client_view->client_view()) |
| 210 return; | 205 return; |
| 211 | 206 |
| 212 const gfx::Rect client_area_rect(non_client_view->client_view()->bounds()); | 207 const gfx::Rect client_area_rect(non_client_view->client_view()->bounds()); |
| 213 SetClientArea(gfx::Insets( | 208 SetClientArea( |
| 214 client_area_rect.y(), client_area_rect.x(), | 209 gfx::Insets( |
| 215 non_client_view->bounds().height() - client_area_rect.bottom(), | 210 client_area_rect.y(), client_area_rect.x(), |
| 216 non_client_view->bounds().width() - client_area_rect.right())); | 211 non_client_view->bounds().height() - client_area_rect.bottom(), |
| 212 non_client_view->bounds().width() - client_area_rect.right()), |
| 213 std::vector<gfx::Rect>()); |
| 217 } | 214 } |
| 218 | 215 |
| 219 void DesktopWindowTreeHostMus::SendHitTestMaskToServer() { | 216 void DesktopWindowTreeHostMus::SendHitTestMaskToServer() { |
| 220 if (!native_widget_delegate_->HasHitTestMask()) { | 217 if (!native_widget_delegate_->HasHitTestMask()) { |
| 221 SetHitTestMask(base::nullopt); | 218 SetHitTestMask(base::nullopt); |
| 222 return; | 219 return; |
| 223 } | 220 } |
| 224 | 221 |
| 225 gfx::Path mask_path; | 222 gfx::Path mask_path; |
| 226 native_widget_delegate_->GetHitTestMask(&mask_path); | 223 native_widget_delegate_->GetHitTestMask(&mask_path); |
| 227 // TODO(jamescook): Use the full path for the mask. | 224 // TODO(jamescook): Use the full path for the mask. |
| 228 gfx::Rect mask_rect = | 225 gfx::Rect mask_rect = |
| 229 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); | 226 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); |
| 230 SetHitTestMask(mask_rect); | 227 SetHitTestMask(mask_rect); |
| 231 } | 228 } |
| 232 | 229 |
| 233 float DesktopWindowTreeHostMus::GetScaleFactor() const { | 230 float DesktopWindowTreeHostMus::GetScaleFactor() const { |
| 234 // TODO(sky): GetDisplayNearestWindow() should take a const aura::Window*. | 231 // TODO(sky): GetDisplayNearestWindow() should take a const aura::Window*. |
| 235 return display::Screen::GetScreen() | 232 return display::Screen::GetScreen() |
| 236 ->GetDisplayNearestWindow(const_cast<aura::Window*>(window())) | 233 ->GetDisplayNearestWindow(const_cast<aura::Window*>(window())) |
| 237 .device_scale_factor(); | 234 .device_scale_factor(); |
| 238 } | 235 } |
| 239 | 236 |
| 240 void DesktopWindowTreeHostMus::SetBoundsInDIP(const gfx::Rect& bounds_in_dip) { | 237 void DesktopWindowTreeHostMus::SetBoundsInDIP(const gfx::Rect& bounds_in_dip) { |
| 241 SetBoundsInPixels(gfx::ConvertRectToPixel(GetScaleFactor(), bounds_in_dip)); | 238 SetBoundsInPixels(gfx::ConvertRectToPixel(GetScaleFactor(), bounds_in_dip)); |
| 242 } | 239 } |
| 243 | 240 |
| 241 bool DesktopWindowTreeHostMus::ShouldSendClientAreaToServer() const { |
| 242 if (!auto_update_client_area_) |
| 243 return false; |
| 244 |
| 245 using WIP = views::Widget::InitParams; |
| 246 const WIP::Type type = desktop_native_widget_aura_->widget_type(); |
| 247 return type == WIP::TYPE_WINDOW || type == WIP::TYPE_PANEL; |
| 248 } |
| 249 |
| 244 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, | 250 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, |
| 245 const Widget::InitParams& params) { | 251 const Widget::InitParams& params) { |
| 246 // Needed so we don't render over the non-client area the window manager | 252 // Needed so we don't render over the non-client area the window manager |
| 247 // renders to. | 253 // renders to. |
| 248 content_window->layer()->SetFillsBoundsOpaquely(false); | 254 content_window->layer()->SetFillsBoundsOpaquely(false); |
| 249 if (!params.bounds.IsEmpty()) | 255 if (!params.bounds.IsEmpty()) |
| 250 SetBoundsInDIP(params.bounds); | 256 SetBoundsInDIP(params.bounds); |
| 251 | 257 |
| 252 cursor_manager_ = base::MakeUnique<wm::CursorManager>( | 258 cursor_manager_ = base::MakeUnique<wm::CursorManager>( |
| 253 base::MakeUnique<NativeCursorManagerMus>(window())); | 259 base::MakeUnique<NativeCursorManagerMus>(window())); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 void DesktopWindowTreeHostMus::EndMoveLoop() { | 553 void DesktopWindowTreeHostMus::EndMoveLoop() { |
| 548 NOTIMPLEMENTED(); | 554 NOTIMPLEMENTED(); |
| 549 } | 555 } |
| 550 | 556 |
| 551 void DesktopWindowTreeHostMus::SetVisibilityChangedAnimationsEnabled( | 557 void DesktopWindowTreeHostMus::SetVisibilityChangedAnimationsEnabled( |
| 552 bool value) { | 558 bool value) { |
| 553 window()->SetProperty(aura::client::kAnimationsDisabledKey, !value); | 559 window()->SetProperty(aura::client::kAnimationsDisabledKey, !value); |
| 554 } | 560 } |
| 555 | 561 |
| 556 NonClientFrameView* DesktopWindowTreeHostMus::CreateNonClientFrameView() { | 562 NonClientFrameView* DesktopWindowTreeHostMus::CreateNonClientFrameView() { |
| 557 if (!ShouldSetClientArea(desktop_native_widget_aura_->widget_type())) | 563 if (!ShouldSendClientAreaToServer()) |
| 558 return nullptr; | 564 return nullptr; |
| 559 | 565 |
| 560 return new ClientSideNonClientFrameView(native_widget_delegate_->AsWidget()); | 566 return new ClientSideNonClientFrameView(native_widget_delegate_->AsWidget()); |
| 561 } | 567 } |
| 562 | 568 |
| 563 bool DesktopWindowTreeHostMus::ShouldUseNativeFrame() const { | 569 bool DesktopWindowTreeHostMus::ShouldUseNativeFrame() const { |
| 564 return false; | 570 return false; |
| 565 } | 571 } |
| 566 | 572 |
| 567 bool DesktopWindowTreeHostMus::ShouldWindowContentsBeTransparent() const { | 573 bool DesktopWindowTreeHostMus::ShouldWindowContentsBeTransparent() const { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 if (window == this->window()) { | 697 if (window == this->window()) { |
| 692 is_active_ = true; | 698 is_active_ = true; |
| 693 desktop_native_widget_aura_->HandleActivationChanged(true); | 699 desktop_native_widget_aura_->HandleActivationChanged(true); |
| 694 } else if (is_active_) { | 700 } else if (is_active_) { |
| 695 is_active_ = false; | 701 is_active_ = false; |
| 696 desktop_native_widget_aura_->HandleActivationChanged(false); | 702 desktop_native_widget_aura_->HandleActivationChanged(false); |
| 697 } | 703 } |
| 698 } | 704 } |
| 699 | 705 |
| 700 } // namespace views | 706 } // namespace views |
| OLD | NEW |