| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/native_widget_mus.h" | 5 #include "ui/views/mus/native_widget_mus.h" |
| 6 | 6 |
| 7 #include "components/mus/public/cpp/window.h" | 7 #include "components/mus/public/cpp/window.h" |
| 8 #include "components/mus/public/interfaces/window_manager.mojom.h" | 8 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 9 #include "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 10 #include "ui/aura/client/default_capture_client.h" | 10 #include "ui/aura/client/default_capture_client.h" |
| 11 #include "ui/aura/layout_manager.h" | 11 #include "ui/aura/layout_manager.h" |
| 12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/base/hit_test.h" |
| 14 #include "ui/compositor/clip_transform_recorder.h" |
| 15 #include "ui/compositor/paint_recorder.h" |
| 16 #include "ui/gfx/canvas.h" |
| 13 #include "ui/native_theme/native_theme_aura.h" | 17 #include "ui/native_theme/native_theme_aura.h" |
| 18 #include "ui/views/mus/window_manager_client_area_insets.h" |
| 14 #include "ui/views/mus/window_tree_host_mus.h" | 19 #include "ui/views/mus/window_tree_host_mus.h" |
| 15 #include "ui/views/widget/widget_delegate.h" | 20 #include "ui/views/widget/widget_delegate.h" |
| 21 #include "ui/views/window/custom_frame_view.h" |
| 16 #include "ui/wm/core/base_focus_rules.h" | 22 #include "ui/wm/core/base_focus_rules.h" |
| 17 #include "ui/wm/core/capture_controller.h" | 23 #include "ui/wm/core/capture_controller.h" |
| 18 #include "ui/wm/core/focus_controller.h" | 24 #include "ui/wm/core/focus_controller.h" |
| 19 | 25 |
| 20 namespace views { | 26 namespace views { |
| 21 namespace { | 27 namespace { |
| 22 | 28 |
| 29 WindowManagerClientAreaInsets* window_manager_client_area_insets = nullptr; |
| 30 |
| 23 // TODO: figure out what this should be. | 31 // TODO: figure out what this should be. |
| 24 class FocusRulesImpl : public wm::BaseFocusRules { | 32 class FocusRulesImpl : public wm::BaseFocusRules { |
| 25 public: | 33 public: |
| 26 FocusRulesImpl() {} | 34 FocusRulesImpl() {} |
| 27 ~FocusRulesImpl() override {} | 35 ~FocusRulesImpl() override {} |
| 28 | 36 |
| 29 bool SupportsChildActivation(aura::Window* window) const override { | 37 bool SupportsChildActivation(aura::Window* window) const override { |
| 30 return true; | 38 return true; |
| 31 } | 39 } |
| 32 | 40 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 54 const gfx::Rect& requested_bounds) override { | 62 const gfx::Rect& requested_bounds) override { |
| 55 SetChildBoundsDirect(child, requested_bounds); | 63 SetChildBoundsDirect(child, requested_bounds); |
| 56 } | 64 } |
| 57 | 65 |
| 58 aura::Window* outer_; | 66 aura::Window* outer_; |
| 59 aura::Window* inner_; | 67 aura::Window* inner_; |
| 60 | 68 |
| 61 DISALLOW_COPY_AND_ASSIGN(ContentWindowLayoutManager); | 69 DISALLOW_COPY_AND_ASSIGN(ContentWindowLayoutManager); |
| 62 }; | 70 }; |
| 63 | 71 |
| 72 // As the window manager renderers the non-client decorations this class does |
| 73 // very little but honor the client area insets from the window manager. |
| 74 class ClientSideNonClientFrameView : public NonClientFrameView { |
| 75 public: |
| 76 explicit ClientSideNonClientFrameView(views::Widget* widget) |
| 77 : widget_(widget) {} |
| 78 ~ClientSideNonClientFrameView() override {} |
| 79 |
| 80 private: |
| 81 // Returns the default values of client area insets from the window manager. |
| 82 static gfx::Insets GetDefaultWindowManagerInsets(bool is_maximized) { |
| 83 if (!window_manager_client_area_insets) |
| 84 return gfx::Insets(); |
| 85 return is_maximized ? window_manager_client_area_insets->maximized_insets |
| 86 : window_manager_client_area_insets->normal_insets; |
| 87 } |
| 88 |
| 89 // NonClientFrameView: |
| 90 gfx::Rect GetBoundsForClientView() const override { |
| 91 gfx::Rect result(GetLocalBounds()); |
| 92 result.Inset(GetDefaultWindowManagerInsets(widget_->IsMaximized())); |
| 93 return result; |
| 94 } |
| 95 gfx::Rect GetWindowBoundsForClientBounds( |
| 96 const gfx::Rect& client_bounds) const override { |
| 97 const gfx::Insets insets( |
| 98 GetDefaultWindowManagerInsets(widget_->IsMaximized())); |
| 99 return gfx::Rect(client_bounds.x() - insets.left(), |
| 100 client_bounds.y() - insets.top(), |
| 101 client_bounds.width() + insets.width(), |
| 102 client_bounds.height() + insets.height()); |
| 103 } |
| 104 int NonClientHitTest(const gfx::Point& point) override { return HTNOWHERE; } |
| 105 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override { |
| 106 // The window manager provides the shape; do nothing. |
| 107 } |
| 108 void ResetWindowControls() override { |
| 109 // TODO(sky): push to wm? |
| 110 } |
| 111 void UpdateWindowIcon() override { |
| 112 // NOTIMPLEMENTED(); |
| 113 } |
| 114 void UpdateWindowTitle() override { |
| 115 // NOTIMPLEMENTED(); |
| 116 } |
| 117 void SizeConstraintsChanged() override { |
| 118 // NOTIMPLEMENTED(); |
| 119 } |
| 120 |
| 121 views::Widget* widget_; |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(ClientSideNonClientFrameView); |
| 124 }; |
| 125 |
| 64 } // namespace | 126 } // namespace |
| 65 | 127 |
| 66 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
| 67 // NativeWidgetMus, public: | 129 // NativeWidgetMus, public: |
| 68 | 130 |
| 69 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, | 131 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, |
| 70 mojo::Shell* shell, | 132 mojo::Shell* shell, |
| 71 mus::Window* window, | 133 mus::Window* window, |
| 72 mus::mojom::SurfaceType surface_type) | 134 mus::mojom::SurfaceType surface_type) |
| 73 : window_(window), | 135 : window_(window), |
| 74 shell_(shell), | 136 shell_(shell), |
| 75 native_widget_delegate_(delegate), | 137 native_widget_delegate_(delegate), |
| 76 surface_type_(surface_type), | 138 surface_type_(surface_type), |
| 77 show_state_before_fullscreen_(mus::mojom::SHOW_STATE_RESTORED), | 139 show_state_before_fullscreen_(mus::mojom::SHOW_STATE_RESTORED), |
| 78 content_(new aura::Window(this)) {} | 140 content_(new aura::Window(this)) {} |
| 79 NativeWidgetMus::~NativeWidgetMus() {} | 141 NativeWidgetMus::~NativeWidgetMus() {} |
| 80 | 142 |
| 143 // static |
| 144 void NativeWidgetMus::SetWindowManagerClientAreaInsets( |
| 145 const WindowManagerClientAreaInsets& insets) { |
| 146 delete window_manager_client_area_insets; |
| 147 // This is called early on, so we don't bother trying to relayout existing |
| 148 // NativeWidgetMus. When we support restarting the WM we'll need to do that. |
| 149 window_manager_client_area_insets = new WindowManagerClientAreaInsets(insets); |
| 150 } |
| 151 |
| 81 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
| 82 // NativeWidgetMus, private: | 153 // NativeWidgetMus, private: |
| 83 | 154 |
| 84 void NativeWidgetMus::UpdateClientAreaInWindowManager() { | 155 void NativeWidgetMus::UpdateClientAreaInWindowManager() { |
| 85 NonClientView* non_client_view = | 156 NonClientView* non_client_view = |
| 86 native_widget_delegate_->AsWidget()->non_client_view(); | 157 native_widget_delegate_->AsWidget()->non_client_view(); |
| 87 if (!non_client_view || !non_client_view->client_view()) | 158 if (!non_client_view || !non_client_view->client_view()) |
| 88 return; | 159 return; |
| 89 | 160 |
| 90 window_->SetClientArea(non_client_view->client_view()->bounds()); | 161 const gfx::Rect client_area_rect(non_client_view->client_view()->bounds()); |
| 162 window_->SetClientArea(gfx::Insets( |
| 163 client_area_rect.y(), client_area_rect.x(), |
| 164 non_client_view->bounds().height() - client_area_rect.bottom(), |
| 165 non_client_view->bounds().width() - client_area_rect.right())); |
| 91 } | 166 } |
| 92 | 167 |
| 93 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
| 94 // NativeWidgetMus, internal::NativeWidgetPrivate implementation: | 169 // NativeWidgetMus, internal::NativeWidgetPrivate implementation: |
| 95 | 170 |
| 171 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { |
| 172 return new ClientSideNonClientFrameView(GetWidget()); |
| 173 } |
| 174 |
| 96 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { | 175 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { |
| 97 window_tree_host_.reset( | 176 window_tree_host_.reset( |
| 98 new WindowTreeHostMus(shell_, window_, surface_type_)); | 177 new WindowTreeHostMus(shell_, window_, surface_type_)); |
| 99 window_tree_host_->InitHost(); | 178 window_tree_host_->InitHost(); |
| 100 | 179 |
| 101 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); | 180 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); |
| 102 | 181 |
| 103 aura::client::SetFocusClient(window_tree_host_->window(), | 182 aura::client::SetFocusClient(window_tree_host_->window(), |
| 104 focus_client_.get()); | 183 focus_client_.get()); |
| 105 aura::client::SetActivationClient(window_tree_host_->window(), | 184 aura::client::SetActivationClient(window_tree_host_->window(), |
| 106 focus_client_.get()); | 185 focus_client_.get()); |
| 107 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); | 186 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); |
| 108 window_tree_host_->window()->SetLayoutManager( | 187 window_tree_host_->window()->SetLayoutManager( |
| 109 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); | 188 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); |
| 110 capture_client_.reset( | 189 capture_client_.reset( |
| 111 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 190 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
| 112 | 191 |
| 113 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 192 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 114 content_->Init(ui::LAYER_TEXTURED); | 193 content_->Init(ui::LAYER_TEXTURED); |
| 115 content_->SetTransparent(true); | 194 content_->SetTransparent(true); |
| 116 content_->SetFillsBoundsCompletely(false); | 195 content_->SetFillsBoundsCompletely(false); |
| 117 | 196 |
| 118 window_tree_host_->window()->AddChild(content_); | 197 window_tree_host_->window()->AddChild(content_); |
| 119 // TODO(beng): much else, see [Desktop]NativeWidgetAura. | 198 // TODO(beng): much else, see [Desktop]NativeWidgetAura. |
| 120 } | 199 } |
| 121 | 200 |
| 122 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { | |
| 123 // NOTIMPLEMENTED(); | |
| 124 return nullptr; | |
| 125 } | |
| 126 | |
| 127 bool NativeWidgetMus::ShouldUseNativeFrame() const { | 201 bool NativeWidgetMus::ShouldUseNativeFrame() const { |
| 128 // NOTIMPLEMENTED(); | 202 // NOTIMPLEMENTED(); |
| 129 return false; | 203 return false; |
| 130 } | 204 } |
| 131 | 205 |
| 132 bool NativeWidgetMus::ShouldWindowContentsBeTransparent() const { | 206 bool NativeWidgetMus::ShouldWindowContentsBeTransparent() const { |
| 133 // NOTIMPLEMENTED(); | 207 // NOTIMPLEMENTED(); |
| 134 return true; | 208 return true; |
| 135 } | 209 } |
| 136 | 210 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 void NativeWidgetMus::RunShellDrag( | 453 void NativeWidgetMus::RunShellDrag( |
| 380 View* view, | 454 View* view, |
| 381 const ui::OSExchangeData& data, | 455 const ui::OSExchangeData& data, |
| 382 const gfx::Point& location, | 456 const gfx::Point& location, |
| 383 int operation, | 457 int operation, |
| 384 ui::DragDropTypes::DragEventSource source) { | 458 ui::DragDropTypes::DragEventSource source) { |
| 385 // NOTIMPLEMENTED(); | 459 // NOTIMPLEMENTED(); |
| 386 } | 460 } |
| 387 | 461 |
| 388 void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) { | 462 void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) { |
| 389 // NOTIMPLEMENTED(); | 463 content_->SchedulePaintInRect(rect); |
| 390 } | 464 } |
| 391 | 465 |
| 392 void NativeWidgetMus::SetCursor(gfx::NativeCursor cursor) { | 466 void NativeWidgetMus::SetCursor(gfx::NativeCursor cursor) { |
| 393 // NOTIMPLEMENTED(); | 467 // NOTIMPLEMENTED(); |
| 394 } | 468 } |
| 395 | 469 |
| 396 bool NativeWidgetMus::IsMouseEventsEnabled() const { | 470 bool NativeWidgetMus::IsMouseEventsEnabled() const { |
| 397 // NOTIMPLEMENTED(); | 471 // NOTIMPLEMENTED(); |
| 398 return true; | 472 return true; |
| 399 } | 473 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 } else { | 649 } else { |
| 576 native_widget_delegate_->OnScrollEvent(event); | 650 native_widget_delegate_->OnScrollEvent(event); |
| 577 } | 651 } |
| 578 } | 652 } |
| 579 | 653 |
| 580 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { | 654 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { |
| 581 native_widget_delegate_->OnGestureEvent(event); | 655 native_widget_delegate_->OnGestureEvent(event); |
| 582 } | 656 } |
| 583 | 657 |
| 584 } // namespace views | 658 } // namespace views |
| OLD | NEW |