Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: ui/views/mus/desktop_window_tree_host_mus.cc

Issue 2507963002: Implement hit tests/client area. (Closed)
Patch Set: add it back Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/mus/desktop_window_tree_host_mus.h ('k') | ui/views/mus/mus_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/drag_drop_client.h" 9 #include "ui/aura/client/drag_drop_client.h"
10 #include "ui/aura/client/focus_client.h" 10 #include "ui/aura/client/focus_client.h"
11 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
12 #include "ui/aura/mus/window_tree_host_mus.h" 12 #include "ui/aura/mus/window_tree_host_mus.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/base/hit_test.h"
14 #include "ui/display/screen.h" 15 #include "ui/display/screen.h"
15 #include "ui/views/corewm/tooltip_aura.h" 16 #include "ui/views/corewm/tooltip_aura.h"
16 #include "ui/views/mus/mus_client.h" 17 #include "ui/views/mus/mus_client.h"
18 #include "ui/views/mus/window_manager_frame_values.h"
17 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 19 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
18 #include "ui/views/widget/native_widget_aura.h" 20 #include "ui/views/widget/native_widget_aura.h"
19 #include "ui/views/widget/widget_delegate.h" 21 #include "ui/views/widget/widget_delegate.h"
20 #include "ui/wm/core/window_util.h" 22 #include "ui/wm/core/window_util.h"
21 #include "ui/wm/public/activation_client.h" 23 #include "ui/wm/public/activation_client.h"
22 24
23 namespace views { 25 namespace views {
24 26
27 namespace {
28
29 // As the window manager renderers the non-client decorations this class does
30 // very little but honor the client area insets from the window manager.
31 class ClientSideNonClientFrameView : public NonClientFrameView {
32 public:
33 explicit ClientSideNonClientFrameView(views::Widget* widget)
34 : widget_(widget) {}
35 ~ClientSideNonClientFrameView() override {}
36
37 private:
38 // Returns the default values of client area insets from the window manager.
39 static gfx::Insets GetDefaultWindowManagerInsets(bool is_maximized) {
40 const WindowManagerFrameValues& values =
41 WindowManagerFrameValues::instance();
42 return is_maximized ? values.maximized_insets : values.normal_insets;
43 }
44
45 // NonClientFrameView:
46 gfx::Rect GetBoundsForClientView() const override {
47 gfx::Rect result(GetLocalBounds());
48 if (widget_->IsFullscreen())
49 return result;
50 result.Inset(GetDefaultWindowManagerInsets(widget_->IsMaximized()));
51 return result;
52 }
53 gfx::Rect GetWindowBoundsForClientBounds(
54 const gfx::Rect& client_bounds) const override {
55 if (widget_->IsFullscreen())
56 return client_bounds;
57
58 const gfx::Insets insets(
59 GetDefaultWindowManagerInsets(widget_->IsMaximized()));
60 return gfx::Rect(client_bounds.x() - insets.left(),
61 client_bounds.y() - insets.top(),
62 client_bounds.width() + insets.width(),
63 client_bounds.height() + insets.height());
64 }
65 int NonClientHitTest(const gfx::Point& point) override { return HTNOWHERE; }
66 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override {
67 // The window manager provides the shape; do nothing.
68 }
69 void ResetWindowControls() override {
70 // TODO(sky): push to wm?
71 }
72
73 // These have no implementation. The Window Manager handles the actual
74 // rendering of the icon/title. See NonClientFrameViewMash. The values
75 // associated with these methods are pushed to the server by the way of
76 // NativeWidgetMus functions.
77 void UpdateWindowIcon() override {}
78 void UpdateWindowTitle() override {}
79 void SizeConstraintsChanged() override {}
80
81 gfx::Size GetPreferredSize() const override {
82 return widget_->non_client_view()
83 ->GetWindowBoundsForClientBounds(
84 gfx::Rect(widget_->client_view()->GetPreferredSize()))
85 .size();
86 }
87 gfx::Size GetMinimumSize() const override {
88 return widget_->non_client_view()
89 ->GetWindowBoundsForClientBounds(
90 gfx::Rect(widget_->client_view()->GetMinimumSize()))
91 .size();
92 }
93 gfx::Size GetMaximumSize() const override {
94 gfx::Size max_size = widget_->client_view()->GetMaximumSize();
95 gfx::Size converted_size =
96 widget_->non_client_view()
97 ->GetWindowBoundsForClientBounds(gfx::Rect(max_size))
98 .size();
99 return gfx::Size(max_size.width() == 0 ? 0 : converted_size.width(),
100 max_size.height() == 0 ? 0 : converted_size.height());
101 }
102
103 views::Widget* widget_;
104
105 DISALLOW_COPY_AND_ASSIGN(ClientSideNonClientFrameView);
106 };
107
108 } // namespace
109
25 DesktopWindowTreeHostMus::DesktopWindowTreeHostMus( 110 DesktopWindowTreeHostMus::DesktopWindowTreeHostMus(
26 internal::NativeWidgetDelegate* native_widget_delegate, 111 internal::NativeWidgetDelegate* native_widget_delegate,
27 DesktopNativeWidgetAura* desktop_native_widget_aura, 112 DesktopNativeWidgetAura* desktop_native_widget_aura,
28 const std::map<std::string, std::vector<uint8_t>>* mus_properties) 113 const std::map<std::string, std::vector<uint8_t>>* mus_properties)
29 : aura::WindowTreeHostMus(MusClient::Get()->window_tree_client(), 114 : aura::WindowTreeHostMus(MusClient::Get()->window_tree_client(),
30 mus_properties), 115 mus_properties),
31 native_widget_delegate_(native_widget_delegate), 116 native_widget_delegate_(native_widget_delegate),
32 desktop_native_widget_aura_(desktop_native_widget_aura), 117 desktop_native_widget_aura_(desktop_native_widget_aura),
33 fullscreen_restore_state_(ui::SHOW_STATE_DEFAULT), 118 fullscreen_restore_state_(ui::SHOW_STATE_DEFAULT),
34 close_widget_factory_(this) { 119 close_widget_factory_(this) {
35 aura::Env::GetInstance()->AddObserver(this); 120 aura::Env::GetInstance()->AddObserver(this);
121 MusClient::Get()->AddObserver(this);
36 // TODO: use display id and bounds if available, likely need to pass in 122 // TODO: use display id and bounds if available, likely need to pass in
37 // InitParams for that. 123 // InitParams for that.
38 } 124 }
39 125
40 DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() { 126 DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() {
127 MusClient::Get()->RemoveObserver(this);
41 aura::Env::GetInstance()->RemoveObserver(this); 128 aura::Env::GetInstance()->RemoveObserver(this);
42 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); 129 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
43 } 130 }
44 131
45 bool DesktopWindowTreeHostMus::IsDocked() const { 132 bool DesktopWindowTreeHostMus::IsDocked() const {
46 return window()->GetProperty(aura::client::kShowStateKey) == 133 return window()->GetProperty(aura::client::kShowStateKey) ==
47 ui::SHOW_STATE_DOCKED; 134 ui::SHOW_STATE_DOCKED;
48 } 135 }
49 136
137 // TODO(erg): In addition to being called on system events, this also needs to
138 // be called after window size changed.
139 void DesktopWindowTreeHostMus::SendClientAreaToServer() {
140 NonClientView* non_client_view =
141 native_widget_delegate_->AsWidget()->non_client_view();
142 if (!non_client_view || !non_client_view->client_view())
143 return;
144
145 const gfx::Rect client_area_rect(non_client_view->client_view()->bounds());
146 SetClientArea(gfx::Insets(
147 client_area_rect.y(), client_area_rect.x(),
148 non_client_view->bounds().height() - client_area_rect.bottom(),
149 non_client_view->bounds().width() - client_area_rect.right()));
150 }
151
152 void DesktopWindowTreeHostMus::SendHitTestMaskToServer() {
153 if (!native_widget_delegate_->HasHitTestMask()) {
154 SetHitTestMask(base::nullopt);
155 return;
156 }
157
158 gfx::Path mask_path;
159 native_widget_delegate_->GetHitTestMask(&mask_path);
160 // TODO(jamescook): Use the full path for the mask.
161 gfx::Rect mask_rect =
162 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
163 SetHitTestMask(mask_rect);
164 }
165
50 void DesktopWindowTreeHostMus::Init(aura::Window* content_window, 166 void DesktopWindowTreeHostMus::Init(aura::Window* content_window,
51 const Widget::InitParams& params) { 167 const Widget::InitParams& params) {
52 // TODO: handle device scale, http://crbug.com/663524. 168 // TODO: handle device scale, http://crbug.com/663524.
53 if (!params.bounds.IsEmpty()) 169 if (!params.bounds.IsEmpty())
54 SetBounds(params.bounds); 170 SetBounds(params.bounds);
55 } 171 }
56 172
57 void DesktopWindowTreeHostMus::OnNativeWidgetCreated( 173 void DesktopWindowTreeHostMus::OnNativeWidgetCreated(
58 const Widget::InitParams& params) { 174 const Widget::InitParams& params) {
59 if (params.parent && params.parent->GetHost()) { 175 if (params.parent && params.parent->GetHost()) {
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 458
343 void DesktopWindowTreeHostMus::EndMoveLoop() { 459 void DesktopWindowTreeHostMus::EndMoveLoop() {
344 NOTIMPLEMENTED(); 460 NOTIMPLEMENTED();
345 } 461 }
346 462
347 void DesktopWindowTreeHostMus::SetVisibilityChangedAnimationsEnabled( 463 void DesktopWindowTreeHostMus::SetVisibilityChangedAnimationsEnabled(
348 bool value) { 464 bool value) {
349 window()->SetProperty(aura::client::kAnimationsDisabledKey, !value); 465 window()->SetProperty(aura::client::kAnimationsDisabledKey, !value);
350 } 466 }
351 467
468 NonClientFrameView* DesktopWindowTreeHostMus::CreateNonClientFrameView() {
469 return new ClientSideNonClientFrameView(native_widget_delegate_->AsWidget());
470 }
471
352 bool DesktopWindowTreeHostMus::ShouldUseNativeFrame() const { 472 bool DesktopWindowTreeHostMus::ShouldUseNativeFrame() const {
353 return false; 473 return false;
354 } 474 }
355 475
356 bool DesktopWindowTreeHostMus::ShouldWindowContentsBeTransparent() const { 476 bool DesktopWindowTreeHostMus::ShouldWindowContentsBeTransparent() const {
357 return false; 477 return false;
358 } 478 }
359 479
360 void DesktopWindowTreeHostMus::FrameTypeChanged() {} 480 void DesktopWindowTreeHostMus::FrameTypeChanged() {}
361 481
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 void DesktopWindowTreeHostMus::SizeConstraintsChanged() { 529 void DesktopWindowTreeHostMus::SizeConstraintsChanged() {
410 Widget* widget = native_widget_delegate_->AsWidget(); 530 Widget* widget = native_widget_delegate_->AsWidget();
411 window()->SetProperty(aura::client::kCanMaximizeKey, 531 window()->SetProperty(aura::client::kCanMaximizeKey,
412 widget->widget_delegate()->CanMaximize()); 532 widget->widget_delegate()->CanMaximize());
413 window()->SetProperty(aura::client::kCanMinimizeKey, 533 window()->SetProperty(aura::client::kCanMinimizeKey,
414 widget->widget_delegate()->CanMinimize()); 534 widget->widget_delegate()->CanMinimize());
415 window()->SetProperty(aura::client::kCanResizeKey, 535 window()->SetProperty(aura::client::kCanResizeKey,
416 widget->widget_delegate()->CanResize()); 536 widget->widget_delegate()->CanResize());
417 } 537 }
418 538
539 void DesktopWindowTreeHostMus::OnWindowManagerFrameValuesChanged() {
540 NonClientView* non_client_view =
541 native_widget_delegate_->AsWidget()->non_client_view();
542 if (non_client_view) {
543 non_client_view->Layout();
544 non_client_view->SchedulePaint();
545 }
546
547 SendClientAreaToServer();
548 SendHitTestMaskToServer();
549 }
550
419 void DesktopWindowTreeHostMus::ShowImpl() { 551 void DesktopWindowTreeHostMus::ShowImpl() {
420 native_widget_delegate_->OnNativeWidgetVisibilityChanging(true); 552 native_widget_delegate_->OnNativeWidgetVisibilityChanging(true);
421 // Using ui::SHOW_STATE_NORMAL matches that of DesktopWindowTreeHostX11. 553 // Using ui::SHOW_STATE_NORMAL matches that of DesktopWindowTreeHostX11.
422 ShowWindowWithState(ui::SHOW_STATE_NORMAL); 554 ShowWindowWithState(ui::SHOW_STATE_NORMAL);
423 WindowTreeHostMus::ShowImpl(); 555 WindowTreeHostMus::ShowImpl();
424 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true); 556 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true);
425 } 557 }
426 558
427 void DesktopWindowTreeHostMus::HideImpl() { 559 void DesktopWindowTreeHostMus::HideImpl() {
428 native_widget_delegate_->OnNativeWidgetVisibilityChanging(false); 560 native_widget_delegate_->OnNativeWidgetVisibilityChanging(false);
(...skipping 23 matching lines...) Expand all
452 if (window == this->window()) { 584 if (window == this->window()) {
453 is_active_ = true; 585 is_active_ = true;
454 desktop_native_widget_aura_->HandleActivationChanged(true); 586 desktop_native_widget_aura_->HandleActivationChanged(true);
455 } else if (is_active_) { 587 } else if (is_active_) {
456 is_active_ = false; 588 is_active_ = false;
457 desktop_native_widget_aura_->HandleActivationChanged(false); 589 desktop_native_widget_aura_->HandleActivationChanged(false);
458 } 590 }
459 } 591 }
460 592
461 } // namespace views 593 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/desktop_window_tree_host_mus.h ('k') | ui/views/mus/mus_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698