| 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 "mash/wm/non_client_frame_controller.h" | 5 #include "ash/mus/non_client_frame_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "ash/mus/bridge/wm_window_mus.h" |
| 14 #include "ash/mus/frame/frame_border_hit_test_controller.h" |
| 15 #include "ash/mus/frame/move_event_handler.h" |
| 16 #include "ash/mus/frame/non_client_frame_view_mash.h" |
| 17 #include "ash/mus/property_util.h" |
| 18 #include "ash/mus/shadow.h" |
| 13 #include "base/macros.h" | 19 #include "base/macros.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 15 #include "components/mus/public/cpp/property_type_converters.h" | 21 #include "components/mus/public/cpp/property_type_converters.h" |
| 16 #include "components/mus/public/cpp/window.h" | 22 #include "components/mus/public/cpp/window.h" |
| 17 #include "components/mus/public/cpp/window_manager_delegate.h" | 23 #include "components/mus/public/cpp/window_manager_delegate.h" |
| 18 #include "components/mus/public/cpp/window_property.h" | 24 #include "components/mus/public/cpp/window_property.h" |
| 19 #include "components/mus/public/interfaces/window_manager.mojom.h" | 25 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 20 #include "components/mus/public/interfaces/window_tree_host.mojom.h" | 26 #include "components/mus/public/interfaces/window_tree_host.mojom.h" |
| 21 #include "mash/wm/bridge/wm_window_mus.h" | |
| 22 #include "mash/wm/frame/frame_border_hit_test_controller.h" | |
| 23 #include "mash/wm/frame/move_event_handler.h" | |
| 24 #include "mash/wm/frame/non_client_frame_view_mash.h" | |
| 25 #include "mash/wm/property_util.h" | |
| 26 #include "mash/wm/shadow.h" | |
| 27 #include "ui/aura/layout_manager.h" | 27 #include "ui/aura/layout_manager.h" |
| 28 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
| 29 #include "ui/aura/window_tree_host.h" | 29 #include "ui/aura/window_tree_host.h" |
| 30 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
| 31 #include "ui/gfx/geometry/vector2d.h" | 31 #include "ui/gfx/geometry/vector2d.h" |
| 32 #include "ui/views/mus/native_widget_mus.h" | 32 #include "ui/views/mus/native_widget_mus.h" |
| 33 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 34 | 34 |
| 35 namespace mash { | 35 namespace ash { |
| 36 namespace wm { | 36 namespace mus { |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // LayoutManager associated with the window created by WindowTreeHost. Resizes | 39 // LayoutManager associated with the window created by WindowTreeHost. Resizes |
| 40 // all children of the parent to match the bounds of the parent. Additionally | 40 // all children of the parent to match the bounds of the parent. Additionally |
| 41 // handles sizing of a Shadow. | 41 // handles sizing of a Shadow. |
| 42 class ContentWindowLayoutManager : public aura::LayoutManager { | 42 class ContentWindowLayoutManager : public aura::LayoutManager { |
| 43 public: | 43 public: |
| 44 ContentWindowLayoutManager(aura::Window* window, Shadow* shadow) | 44 ContentWindowLayoutManager(aura::Window* window, Shadow* shadow) |
| 45 : window_(window), shadow_(shadow) { | 45 : window_(window), shadow_(shadow) { |
| 46 OnWindowResized(); | 46 OnWindowResized(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 aura::Window* window_; | 81 aura::Window* window_; |
| 82 Shadow* shadow_; | 82 Shadow* shadow_; |
| 83 | 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(ContentWindowLayoutManager); | 84 DISALLOW_COPY_AND_ASSIGN(ContentWindowLayoutManager); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class WmNativeWidgetMus : public views::NativeWidgetMus { | 87 class WmNativeWidgetMus : public views::NativeWidgetMus { |
| 88 public: | 88 public: |
| 89 WmNativeWidgetMus(views::internal::NativeWidgetDelegate* delegate, | 89 WmNativeWidgetMus(views::internal::NativeWidgetDelegate* delegate, |
| 90 shell::Connector* connector, | 90 shell::Connector* connector, |
| 91 mus::Window* window, | 91 ::mus::Window* window, |
| 92 mus::WindowManagerClient* window_manager_client) | 92 ::mus::WindowManagerClient* window_manager_client) |
| 93 : NativeWidgetMus(delegate, | 93 : NativeWidgetMus(delegate, |
| 94 connector, | 94 connector, |
| 95 window, | 95 window, |
| 96 mus::mojom::SurfaceType::UNDERLAY), | 96 ::mus::mojom::SurfaceType::UNDERLAY), |
| 97 window_manager_client_(window_manager_client) {} | 97 window_manager_client_(window_manager_client) {} |
| 98 ~WmNativeWidgetMus() override { | 98 ~WmNativeWidgetMus() override {} |
| 99 } | |
| 100 | 99 |
| 101 // NativeWidgetMus: | 100 // NativeWidgetMus: |
| 102 views::NonClientFrameView* CreateNonClientFrameView() override { | 101 views::NonClientFrameView* CreateNonClientFrameView() override { |
| 103 views::Widget* widget = | 102 views::Widget* widget = |
| 104 static_cast<views::internal::NativeWidgetPrivate*>(this)->GetWidget(); | 103 static_cast<views::internal::NativeWidgetPrivate*>(this)->GetWidget(); |
| 105 NonClientFrameViewMash* frame_view = | 104 NonClientFrameViewMash* frame_view = |
| 106 new NonClientFrameViewMash(widget, window()); | 105 new NonClientFrameViewMash(widget, window()); |
| 107 move_event_handler_.reset(new MoveEventHandler( | 106 move_event_handler_.reset(new MoveEventHandler( |
| 108 window(), window_manager_client_, GetNativeView())); | 107 window(), window_manager_client_, GetNativeView())); |
| 109 return frame_view; | 108 return frame_view; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 139 // This pushes the client area to the WS. We don't want to do that as | 138 // This pushes the client area to the WS. We don't want to do that as |
| 140 // the client area should come from the client, not us. | 139 // the client area should come from the client, not us. |
| 141 } | 140 } |
| 142 | 141 |
| 143 private: | 142 private: |
| 144 // The shadow, may be null. | 143 // The shadow, may be null. |
| 145 std::unique_ptr<Shadow> shadow_; | 144 std::unique_ptr<Shadow> shadow_; |
| 146 | 145 |
| 147 std::unique_ptr<MoveEventHandler> move_event_handler_; | 146 std::unique_ptr<MoveEventHandler> move_event_handler_; |
| 148 | 147 |
| 149 mus::WindowManagerClient* window_manager_client_; | 148 ::mus::WindowManagerClient* window_manager_client_; |
| 150 | 149 |
| 151 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetMus); | 150 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetMus); |
| 152 }; | 151 }; |
| 153 | 152 |
| 154 class ClientViewMus : public views::ClientView { | 153 class ClientViewMus : public views::ClientView { |
| 155 public: | 154 public: |
| 156 ClientViewMus(views::Widget* widget, | 155 ClientViewMus(views::Widget* widget, |
| 157 views::View* contents_view, | 156 views::View* contents_view, |
| 158 NonClientFrameController* frame_controller) | 157 NonClientFrameController* frame_controller) |
| 159 : views::ClientView(widget, contents_view), | 158 : views::ClientView(widget, contents_view), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 NonClientFrameController* frame_controller_; | 172 NonClientFrameController* frame_controller_; |
| 174 | 173 |
| 175 DISALLOW_COPY_AND_ASSIGN(ClientViewMus); | 174 DISALLOW_COPY_AND_ASSIGN(ClientViewMus); |
| 176 }; | 175 }; |
| 177 | 176 |
| 178 } // namespace | 177 } // namespace |
| 179 | 178 |
| 180 // static | 179 // static |
| 181 void NonClientFrameController::Create( | 180 void NonClientFrameController::Create( |
| 182 shell::Connector* connector, | 181 shell::Connector* connector, |
| 183 mus::Window* parent, | 182 ::mus::Window* parent, |
| 184 mus::Window* window, | 183 ::mus::Window* window, |
| 185 mus::WindowManagerClient* window_manager_client) { | 184 ::mus::WindowManagerClient* window_manager_client) { |
| 186 new NonClientFrameController(connector, parent, window, | 185 new NonClientFrameController(connector, parent, window, |
| 187 window_manager_client); | 186 window_manager_client); |
| 188 } | 187 } |
| 189 | 188 |
| 190 // static | 189 // static |
| 191 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() { | 190 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() { |
| 192 return NonClientFrameViewMash::GetPreferredClientAreaInsets(); | 191 return NonClientFrameViewMash::GetPreferredClientAreaInsets(); |
| 193 } | 192 } |
| 194 | 193 |
| 195 // static | 194 // static |
| 196 int NonClientFrameController::GetMaxTitleBarButtonWidth() { | 195 int NonClientFrameController::GetMaxTitleBarButtonWidth() { |
| 197 return NonClientFrameViewMash::GetMaxTitleBarButtonWidth(); | 196 return NonClientFrameViewMash::GetMaxTitleBarButtonWidth(); |
| 198 } | 197 } |
| 199 | 198 |
| 200 NonClientFrameController::NonClientFrameController( | 199 NonClientFrameController::NonClientFrameController( |
| 201 shell::Connector* connector, | 200 shell::Connector* connector, |
| 202 mus::Window* parent, | 201 ::mus::Window* parent, |
| 203 mus::Window* window, | 202 ::mus::Window* window, |
| 204 mus::WindowManagerClient* window_manager_client) | 203 ::mus::WindowManagerClient* window_manager_client) |
| 205 : widget_(new views::Widget), window_(window) { | 204 : widget_(new views::Widget), window_(window) { |
| 206 WmWindowMus* wm_window = WmWindowMus::Get(window); | 205 WmWindowMus* wm_window = WmWindowMus::Get(window); |
| 207 wm_window->set_widget(widget_, WmWindowMus::WidgetCreationType::FOR_CLIENT); | 206 wm_window->set_widget(widget_, WmWindowMus::WidgetCreationType::FOR_CLIENT); |
| 208 window_->AddObserver(this); | 207 window_->AddObserver(this); |
| 209 | 208 |
| 210 // To simplify things this code creates a Widget. While a Widget is created | 209 // To simplify things this code creates a Widget. While a Widget is created |
| 211 // we need to ensure we don't inadvertently change random properties of the | 210 // we need to ensure we don't inadvertently change random properties of the |
| 212 // underlying mus::Window. For example, showing the Widget shouldn't change | 211 // underlying mus::Window. For example, showing the Widget shouldn't change |
| 213 // the bounds of the mus::Window in anyway. | 212 // the bounds of the mus::Window in anyway. |
| 214 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 213 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 233 window, gfx::Vector2d(shadow_inset, shadow_inset), extended_hit_region); | 232 window, gfx::Vector2d(shadow_inset, shadow_inset), extended_hit_region); |
| 234 } | 233 } |
| 235 | 234 |
| 236 NonClientFrameController::~NonClientFrameController() { | 235 NonClientFrameController::~NonClientFrameController() { |
| 237 if (window_) | 236 if (window_) |
| 238 window_->RemoveObserver(this); | 237 window_->RemoveObserver(this); |
| 239 } | 238 } |
| 240 | 239 |
| 241 base::string16 NonClientFrameController::GetWindowTitle() const { | 240 base::string16 NonClientFrameController::GetWindowTitle() const { |
| 242 if (!window_->HasSharedProperty( | 241 if (!window_->HasSharedProperty( |
| 243 mus::mojom::WindowManager::kWindowTitle_Property)) { | 242 ::mus::mojom::WindowManager::kWindowTitle_Property)) { |
| 244 return base::string16(); | 243 return base::string16(); |
| 245 } | 244 } |
| 246 | 245 |
| 247 base::string16 title = window_->GetSharedProperty<base::string16>( | 246 base::string16 title = window_->GetSharedProperty<base::string16>( |
| 248 mus::mojom::WindowManager::kWindowTitle_Property); | 247 ::mus::mojom::WindowManager::kWindowTitle_Property); |
| 249 | 248 |
| 250 if (IsWindowJanky(window_)) | 249 if (IsWindowJanky(window_)) |
| 251 title += base::ASCIIToUTF16(" !! Not responding !!"); | 250 title += base::ASCIIToUTF16(" !! Not responding !!"); |
| 252 | 251 |
| 253 return title; | 252 return title; |
| 254 } | 253 } |
| 255 | 254 |
| 256 views::View* NonClientFrameController::GetContentsView() { | 255 views::View* NonClientFrameController::GetContentsView() { |
| 257 return this; | 256 return this; |
| 258 } | 257 } |
| 259 | 258 |
| 260 bool NonClientFrameController::CanResize() const { | 259 bool NonClientFrameController::CanResize() const { |
| 261 return window_ && | 260 return window_ && |
| 262 (GetResizeBehavior(window_) & mus::mojom::kResizeBehaviorCanResize) != | 261 (GetResizeBehavior(window_) & |
| 263 0; | 262 ::mus::mojom::kResizeBehaviorCanResize) != 0; |
| 264 } | 263 } |
| 265 | 264 |
| 266 bool NonClientFrameController::CanMaximize() const { | 265 bool NonClientFrameController::CanMaximize() const { |
| 267 return window_ && | 266 return window_ && |
| 268 (GetResizeBehavior(window_) & | 267 (GetResizeBehavior(window_) & |
| 269 mus::mojom::kResizeBehaviorCanMaximize) != 0; | 268 ::mus::mojom::kResizeBehaviorCanMaximize) != 0; |
| 270 } | 269 } |
| 271 | 270 |
| 272 bool NonClientFrameController::CanMinimize() const { | 271 bool NonClientFrameController::CanMinimize() const { |
| 273 return window_ && | 272 return window_ && |
| 274 (GetResizeBehavior(window_) & | 273 (GetResizeBehavior(window_) & |
| 275 mus::mojom::kResizeBehaviorCanMinimize) != 0; | 274 ::mus::mojom::kResizeBehaviorCanMinimize) != 0; |
| 276 } | 275 } |
| 277 | 276 |
| 278 bool NonClientFrameController::ShouldShowWindowTitle() const { | 277 bool NonClientFrameController::ShouldShowWindowTitle() const { |
| 279 // Only draw the title if the client hasn't declared any additional client | 278 // Only draw the title if the client hasn't declared any additional client |
| 280 // areas which might conflict with it. | 279 // areas which might conflict with it. |
| 281 return window_ && window_->additional_client_areas().empty(); | 280 return window_ && window_->additional_client_areas().empty(); |
| 282 } | 281 } |
| 283 | 282 |
| 284 views::ClientView* NonClientFrameController::CreateClientView( | 283 views::ClientView* NonClientFrameController::CreateClientView( |
| 285 views::Widget* widget) { | 284 views::Widget* widget) { |
| 286 return new ClientViewMus(widget, GetContentsView(), this); | 285 return new ClientViewMus(widget, GetContentsView(), this); |
| 287 } | 286 } |
| 288 | 287 |
| 289 void NonClientFrameController::OnWindowSharedPropertyChanged( | 288 void NonClientFrameController::OnWindowSharedPropertyChanged( |
| 290 mus::Window* window, | 289 ::mus::Window* window, |
| 291 const std::string& name, | 290 const std::string& name, |
| 292 const std::vector<uint8_t>* old_data, | 291 const std::vector<uint8_t>* old_data, |
| 293 const std::vector<uint8_t>* new_data) { | 292 const std::vector<uint8_t>* new_data) { |
| 294 if (name == mus::mojom::WindowManager::kResizeBehavior_Property) | 293 if (name == ::mus::mojom::WindowManager::kResizeBehavior_Property) |
| 295 widget_->OnSizeConstraintsChanged(); | 294 widget_->OnSizeConstraintsChanged(); |
| 296 else if (name == mus::mojom::WindowManager::kWindowTitle_Property) | 295 else if (name == ::mus::mojom::WindowManager::kWindowTitle_Property) |
| 297 widget_->UpdateWindowTitle(); | 296 widget_->UpdateWindowTitle(); |
| 298 } | 297 } |
| 299 | 298 |
| 300 void NonClientFrameController::OnWindowLocalPropertyChanged( | 299 void NonClientFrameController::OnWindowLocalPropertyChanged( |
| 301 mus::Window* window, | 300 ::mus::Window* window, |
| 302 const void* key, | 301 const void* key, |
| 303 intptr_t old) { | 302 intptr_t old) { |
| 304 if (IsWindowJankyProperty(key)) { | 303 if (IsWindowJankyProperty(key)) { |
| 305 widget_->UpdateWindowTitle(); | 304 widget_->UpdateWindowTitle(); |
| 306 widget_->non_client_view()->frame_view()->SchedulePaint(); | 305 widget_->non_client_view()->frame_view()->SchedulePaint(); |
| 307 } | 306 } |
| 308 } | 307 } |
| 309 | 308 |
| 310 void NonClientFrameController::OnWindowDestroyed(mus::Window* window) { | 309 void NonClientFrameController::OnWindowDestroyed(::mus::Window* window) { |
| 311 window_->RemoveObserver(this); | 310 window_->RemoveObserver(this); |
| 312 window_ = nullptr; | 311 window_ = nullptr; |
| 313 } | 312 } |
| 314 | 313 |
| 315 } // namespace wm | 314 } // namespace mus |
| 316 } // namespace mash | 315 } // namespace ash |
| OLD | NEW |