| 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 "mash/simple_wm/simple_wm.h" | 5 #include "mash/simple_wm/simple_wm.h" |
| 6 | 6 |
| 7 #include "base/observer_list.h" | 7 #include "base/observer_list.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "mash/simple_wm/move_event_handler.h" | 9 #include "mash/simple_wm/move_event_handler.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/aura/layout_manager.h" | 11 #include "ui/aura/layout_manager.h" |
| 12 #include "ui/display/screen_base.h" | 12 #include "ui/display/screen_base.h" |
| 13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/geometry/mojo/geometry.mojom.h" | 14 #include "ui/gfx/geometry/mojo/geometry.mojom.h" |
| 15 #include "ui/views/controls/button/md_text_button.h" | 15 #include "ui/views/controls/button/md_text_button.h" |
| 16 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/mus/aura_init.h" | 17 #include "ui/views/mus/aura_init.h" |
| 18 #include "ui/views/mus/mus_client.h" | 18 #include "ui/views/mus/mus_client.h" |
| 19 #include "ui/views/widget/native_widget_aura.h" | 19 #include "ui/views/widget/native_widget_aura.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
| 22 #include "ui/wm/core/default_activation_client.h" | 22 #include "ui/wm/core/default_activation_client.h" |
| 23 | 23 |
| 24 namespace simple_wm { | 24 namespace simple_wm { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const int kNonClientTopHeight = 24; | 28 const int kNonClientTopHeight = 24; |
| 29 const int kNonClientSize = 5; | 29 const int kNonClientSize = 5; |
| 30 const int kNonClientMaximizedTopOverlap = 4; |
| 30 | 31 |
| 31 } // namespace | 32 } // namespace |
| 32 | 33 |
| 33 class SimpleWM::WindowListModelObserver { | 34 class SimpleWM::WindowListModelObserver { |
| 34 public: | 35 public: |
| 35 virtual void OnWindowAddedOrRemoved() = 0; | 36 virtual void OnWindowAddedOrRemoved() = 0; |
| 36 virtual void OnWindowTitleChanged(size_t index, | 37 virtual void OnWindowTitleChanged(size_t index, |
| 37 const base::string16& title) = 0; | 38 const base::string16& title) = 0; |
| 38 }; | 39 }; |
| 39 | 40 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 for (int i = 0; i < child_count(); ++i) { | 127 for (int i = 0; i < child_count(); ++i) { |
| 127 View* v = child_at(i); | 128 View* v = child_at(i); |
| 128 gfx::Size ps = v->GetPreferredSize(); | 129 gfx::Size ps = v->GetPreferredSize(); |
| 129 gfx::Rect bounds(x_offset, kButtonSpacing, ps.width(), ps.height()); | 130 gfx::Rect bounds(x_offset, kButtonSpacing, ps.width(), ps.height()); |
| 130 v->SetBoundsRect(bounds); | 131 v->SetBoundsRect(bounds); |
| 131 x_offset = bounds.right() + kButtonSpacing; | 132 x_offset = bounds.right() + kButtonSpacing; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 void OnPaint(gfx::Canvas* canvas) override { | 135 void OnPaint(gfx::Canvas* canvas) override { |
| 135 canvas->DrawColor(SK_ColorLTGRAY); | 136 canvas->DrawColor(SK_ColorLTGRAY); |
| 137 gfx::Rect stroke_bounds = GetLocalBounds(); |
| 138 stroke_bounds.set_height(1); |
| 139 canvas->FillRect(stroke_bounds, SK_ColorDKGRAY); |
| 136 } | 140 } |
| 137 gfx::Size GetPreferredSize() const override { | 141 gfx::Size GetPreferredSize() const override { |
| 138 std::unique_ptr<views::MdTextButton> measure_button( | 142 std::unique_ptr<views::MdTextButton> measure_button( |
| 139 views::MdTextButton::Create(nullptr, base::UTF8ToUTF16("Sample"))); | 143 views::MdTextButton::Create(nullptr, base::UTF8ToUTF16("Sample"))); |
| 140 int height = | 144 int height = |
| 141 measure_button->GetPreferredSize().height() + 2 * kButtonSpacing; | 145 measure_button->GetPreferredSize().height() + 2 * kButtonSpacing; |
| 142 return gfx::Size(0, height); | 146 return gfx::Size(0, height); |
| 143 } | 147 } |
| 144 | 148 |
| 145 private: | 149 private: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 : base::UTF8ToUTF16("(Window)"); | 209 : base::UTF8ToUTF16("(Window)"); |
| 206 // TODO(beng): quick hack to cause WindowObserver::OnWindowTitleChanged to | 210 // TODO(beng): quick hack to cause WindowObserver::OnWindowTitleChanged to |
| 207 // fire. | 211 // fire. |
| 208 GetWidget()->GetNativeWindow()->SetTitle(title); | 212 GetWidget()->GetNativeWindow()->SetTitle(title); |
| 209 return title; | 213 return title; |
| 210 } | 214 } |
| 211 void Layout() override { | 215 void Layout() override { |
| 212 // Client offsets are applied automatically by the window service. | 216 // Client offsets are applied automatically by the window service. |
| 213 gfx::Rect parent_bounds = GetWidget()->GetNativeWindow()->bounds(); | 217 gfx::Rect parent_bounds = GetWidget()->GetNativeWindow()->bounds(); |
| 214 parent_bounds.set_origin(gfx::Point()); | 218 parent_bounds.set_origin(gfx::Point()); |
| 219 |
| 220 if (GetWidget()->IsMaximized()) { |
| 221 parent_bounds.Inset(-kNonClientSize, -kNonClientMaximizedTopOverlap, |
| 222 -kNonClientSize, -kNonClientSize); |
| 223 } |
| 224 |
| 215 client_window_->SetBounds(parent_bounds); | 225 client_window_->SetBounds(parent_bounds); |
| 216 } | 226 } |
| 227 bool CanMaximize() const override { |
| 228 return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) & |
| 229 ui::mojom::kResizeBehaviorCanMaximize) != 0; |
| 230 } |
| 231 |
| 232 bool CanMinimize() const override { |
| 233 return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) & |
| 234 ui::mojom::kResizeBehaviorCanMinimize) != 0; |
| 235 } |
| 236 |
| 237 bool CanResize() const override { |
| 238 return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) & |
| 239 ui::mojom::kResizeBehaviorCanResize) != 0; |
| 240 } |
| 217 | 241 |
| 218 // aura::WindowObserver: | 242 // aura::WindowObserver: |
| 219 void OnWindowPropertyChanged(aura::Window* window, const void* key, | 243 void OnWindowPropertyChanged(aura::Window* window, const void* key, |
| 220 intptr_t old) override { | 244 intptr_t old) override { |
| 221 if (key == aura::client::kTitleKey) | 245 if (key == aura::client::kTitleKey) |
| 222 GetWidget()->UpdateWindowTitle(); | 246 GetWidget()->UpdateWindowTitle(); |
| 247 else if (key == aura::client::kResizeBehaviorKey) |
| 248 GetWidget()->non_client_view()->frame_view()->Layout(); |
| 223 } | 249 } |
| 224 | 250 |
| 225 aura::Window* client_window_; | 251 aura::Window* client_window_; |
| 226 std::unique_ptr<MoveEventHandler> move_event_handler_; | 252 std::unique_ptr<MoveEventHandler> move_event_handler_; |
| 227 | 253 |
| 228 DISALLOW_COPY_AND_ASSIGN(FrameView); | 254 DISALLOW_COPY_AND_ASSIGN(FrameView); |
| 229 }; | 255 }; |
| 230 | 256 |
| 257 class SimpleWM::WorkspaceLayoutManager : public aura::WindowObserver { |
| 258 public: |
| 259 explicit WorkspaceLayoutManager(aura::Window* window_root) |
| 260 : window_root_(window_root) {} |
| 261 ~WorkspaceLayoutManager() override {} |
| 262 |
| 263 private: |
| 264 // aura::WindowObserver: |
| 265 void OnWindowPropertyChanged(aura::Window* window, const void* key, |
| 266 intptr_t old) override { |
| 267 if (key == aura::client::kShowStateKey) { |
| 268 ui::WindowShowState show_state = |
| 269 window->GetProperty(aura::client::kShowStateKey); |
| 270 switch (show_state) { |
| 271 case ui::SHOW_STATE_NORMAL: |
| 272 window->Show(); |
| 273 window->SetBounds( |
| 274 *window->GetProperty(aura::client::kRestoreBoundsKey)); |
| 275 break; |
| 276 case ui::SHOW_STATE_MINIMIZED: |
| 277 window->Hide(); |
| 278 break; |
| 279 case ui::SHOW_STATE_MAXIMIZED: |
| 280 window->Show(); |
| 281 window->SetProperty(aura::client::kRestoreBoundsKey, |
| 282 new gfx::Rect(window->bounds())); |
| 283 window->SetBounds(gfx::Rect(window_root_->bounds().size())); |
| 284 break; |
| 285 default: |
| 286 NOTREACHED(); |
| 287 break; |
| 288 } |
| 289 } |
| 290 } |
| 291 void OnWindowDestroying(aura::Window* window) override { |
| 292 window->RemoveObserver(this); |
| 293 } |
| 294 |
| 295 aura::Window* window_root_; |
| 296 |
| 297 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager); |
| 298 }; |
| 299 |
| 231 class SimpleWM::DisplayLayoutManager : public aura::LayoutManager { | 300 class SimpleWM::DisplayLayoutManager : public aura::LayoutManager { |
| 232 public: | 301 public: |
| 233 DisplayLayoutManager(aura::Window* display_root, | 302 DisplayLayoutManager(aura::Window* display_root, |
| 234 aura::Window* window_root, | 303 aura::Window* window_root, |
| 235 SimpleWM::WindowListView* window_list_view) | 304 SimpleWM::WindowListView* window_list_view) |
| 236 : display_root_(display_root), | 305 : display_root_(display_root), |
| 237 window_root_(window_root), | 306 window_root_(window_root), |
| 238 window_list_view_(window_list_view) {} | 307 window_list_view_(window_list_view) {} |
| 239 ~DisplayLayoutManager() override {} | 308 ~DisplayLayoutManager() override {} |
| 240 | 309 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 FrameView* frame_view = new FrameView(client_window); | 443 FrameView* frame_view = new FrameView(client_window); |
| 375 params.delegate = frame_view; | 444 params.delegate = frame_view; |
| 376 params.native_widget = frame_native_widget; | 445 params.native_widget = frame_native_widget; |
| 377 params.parent = window_root_; | 446 params.parent = window_root_; |
| 378 params.bounds = gfx::Rect(10, 10, 500, 500); | 447 params.bounds = gfx::Rect(10, 10, 500, 500); |
| 379 frame_widget->Init(params); | 448 frame_widget->Init(params); |
| 380 frame_widget->Show(); | 449 frame_widget->Show(); |
| 381 frame_view->Init(); | 450 frame_view->Init(); |
| 382 | 451 |
| 383 frame_widget->GetNativeWindow()->AddChild(client_window); | 452 frame_widget->GetNativeWindow()->AddChild(client_window); |
| 453 frame_widget->GetNativeWindow()->AddObserver(workspace_layout_manager_.get()); |
| 384 | 454 |
| 385 client_window_to_frame_view_[client_window] = frame_view; | 455 client_window_to_frame_view_[client_window] = frame_view; |
| 386 // TODO(beng): probably need to observe client_window from now on so we can | 456 // TODO(beng): probably need to observe client_window from now on so we can |
| 387 // clean up this map. | 457 // clean up this map. |
| 388 | 458 |
| 389 return client_window; | 459 return client_window; |
| 390 } | 460 } |
| 391 | 461 |
| 392 void SimpleWM::OnWmClientJankinessChanged( | 462 void SimpleWM::OnWmClientJankinessChanged( |
| 393 const std::set<aura::Window*>& client_windows, | 463 const std::set<aura::Window*>& client_windows, |
| 394 bool janky) { | 464 bool janky) { |
| 395 // Don't care. | 465 // Don't care. |
| 396 } | 466 } |
| 397 | 467 |
| 398 void SimpleWM::OnWmWillCreateDisplay(const display::Display& display) { | 468 void SimpleWM::OnWmWillCreateDisplay(const display::Display& display) { |
| 399 screen_->display_list().AddDisplay(display, | 469 screen_->display_list().AddDisplay(display, |
| 400 display::DisplayList::Type::PRIMARY); | 470 display::DisplayList::Type::PRIMARY); |
| 401 } | 471 } |
| 402 | 472 |
| 403 void SimpleWM::OnWmNewDisplay( | 473 void SimpleWM::OnWmNewDisplay( |
| 404 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, | 474 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| 405 const display::Display& display) { | 475 const display::Display& display) { |
| 406 // Only handles a single root. | 476 // Only handles a single root. |
| 407 DCHECK(!window_root_); | 477 DCHECK(!window_root_); |
| 408 window_tree_host_ = std::move(window_tree_host); | 478 window_tree_host_ = std::move(window_tree_host); |
| 409 window_tree_host_->InitHost(); | 479 window_tree_host_->InitHost(); |
| 410 window_tree_host_->window()->Show(); | 480 window_tree_host_->window()->Show(); |
| 411 display_root_ = window_tree_host_->window(); | 481 display_root_ = window_tree_host_->window(); |
| 412 window_root_ = new aura::Window(nullptr); | 482 window_root_ = new aura::Window(nullptr); |
| 413 window_root_->Init(ui::LAYER_NOT_DRAWN); | 483 window_root_->Init(ui::LAYER_SOLID_COLOR); |
| 484 window_root_->layer()->SetColor(SK_ColorWHITE); |
| 414 display_root_->AddChild(window_root_); | 485 display_root_->AddChild(window_root_); |
| 415 window_root_->Show(); | 486 window_root_->Show(); |
| 487 workspace_layout_manager_ = |
| 488 base::MakeUnique<WorkspaceLayoutManager>(window_root_); |
| 416 | 489 |
| 417 window_list_model_ = base::MakeUnique<WindowListModel>(window_root_); | 490 window_list_model_ = base::MakeUnique<WindowListModel>(window_root_); |
| 418 | 491 |
| 419 views::Widget* window_list_widget = new views::Widget; | 492 views::Widget* window_list_widget = new views::Widget; |
| 420 views::NativeWidgetAura* window_list_widget_native_widget = | 493 views::NativeWidgetAura* window_list_widget_native_widget = |
| 421 new views::NativeWidgetAura(window_list_widget, true); | 494 new views::NativeWidgetAura(window_list_widget, true); |
| 422 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 495 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 423 WindowListView* window_list_view = | 496 WindowListView* window_list_view = |
| 424 new WindowListView(window_list_model_.get(), | 497 new WindowListView(window_list_model_.get(), |
| 425 base::Bind(&SimpleWM::OnWindowListViewItemActivated, | 498 base::Bind(&SimpleWM::OnWindowListViewItemActivated, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 const gfx::Insets& insets, | 543 const gfx::Insets& insets, |
| 471 const std::vector<gfx::Rect>& additional_client_areas) {} | 544 const std::vector<gfx::Rect>& additional_client_areas) {} |
| 472 | 545 |
| 473 SimpleWM::FrameView* SimpleWM::GetFrameViewForClientWindow( | 546 SimpleWM::FrameView* SimpleWM::GetFrameViewForClientWindow( |
| 474 aura::Window* client_window) { | 547 aura::Window* client_window) { |
| 475 auto it = client_window_to_frame_view_.find(client_window); | 548 auto it = client_window_to_frame_view_.find(client_window); |
| 476 return it != client_window_to_frame_view_.end() ? it->second : nullptr; | 549 return it != client_window_to_frame_view_.end() ? it->second : nullptr; |
| 477 } | 550 } |
| 478 | 551 |
| 479 void SimpleWM::OnWindowListViewItemActivated(aura::Window* window) { | 552 void SimpleWM::OnWindowListViewItemActivated(aura::Window* window) { |
| 553 window->Show(); |
| 480 aura::client::ActivationClient* activation_client = | 554 aura::client::ActivationClient* activation_client = |
| 481 aura::client::GetActivationClient(window->GetRootWindow()); | 555 aura::client::GetActivationClient(window->GetRootWindow()); |
| 482 activation_client->ActivateWindow(window); | 556 activation_client->ActivateWindow(window); |
| 483 } | 557 } |
| 484 | 558 |
| 485 } // namespace simple_wm | 559 } // namespace simple_wm |
| OLD | NEW |