| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "examples/wm_flow/wm/frame_controller.h" | 5 #include "examples/wm_flow/wm/frame_controller.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 10 #include "mojo/services/view_manager/public/cpp/view.h" | 10 #include "mojo/services/view_manager/public/cpp/view.h" |
| 11 #include "mojo/views/native_widget_mojo.h" | 11 #include "mojo/views/native_widget_mojo.h" |
| 12 #include "services/window_manager/capture_controller.h" |
| 12 #include "services/window_manager/window_manager_app.h" | 13 #include "services/window_manager/window_manager_app.h" |
| 13 #include "ui/views/background.h" | 14 #include "ui/views/background.h" |
| 15 #include "ui/views/controls/button/checkbox.h" |
| 14 #include "ui/views/controls/button/label_button.h" | 16 #include "ui/views/controls/button/label_button.h" |
| 15 #include "ui/views/layout/layout_manager.h" | 17 #include "ui/views/layout/layout_manager.h" |
| 16 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 17 #include "ui/wm/public/activation_client.h" | 19 #include "ui/wm/public/activation_client.h" |
| 18 | 20 |
| 19 class FrameController::LayoutManager : public views::LayoutManager, | 21 class FrameController::LayoutManager : public views::LayoutManager, |
| 20 public views::ButtonListener { | 22 public views::ButtonListener { |
| 21 public: | 23 public: |
| 22 explicit LayoutManager(FrameController* controller) | 24 explicit LayoutManager(FrameController* controller) |
| 23 : controller_(controller), | 25 : controller_(controller), |
| 26 capture_checkbox_( |
| 27 new views::Checkbox(base::ASCIIToUTF16("Capture"))), |
| 24 close_button_( | 28 close_button_( |
| 25 new views::LabelButton(this, base::ASCIIToUTF16("Begone"))), | 29 new views::LabelButton(this, base::ASCIIToUTF16("Begone"))), |
| 26 maximize_button_( | 30 maximize_button_( |
| 27 new views::LabelButton(this, base::ASCIIToUTF16("Embiggen"))) {} | 31 new views::LabelButton(this, base::ASCIIToUTF16("Embiggen"))) { |
| 32 capture_checkbox_->set_listener(this); |
| 33 } |
| 28 virtual ~LayoutManager() {} | 34 virtual ~LayoutManager() {} |
| 29 | 35 |
| 30 private: | 36 private: |
| 31 static const int kButtonFrameMargin = 5; | 37 static const int kButtonFrameMargin = 5; |
| 32 static const int kButtonFrameSpacing = 2; | 38 static const int kButtonFrameSpacing = 2; |
| 33 static const int kFrameSize = 10; | 39 static const int kFrameSize = 10; |
| 34 | 40 |
| 35 // Overridden from views::LayoutManager: | 41 // Overridden from views::LayoutManager: |
| 36 virtual void Installed(views::View* host) override { | 42 virtual void Installed(views::View* host) override { |
| 43 host->AddChildView(capture_checkbox_); |
| 37 host->AddChildView(close_button_); | 44 host->AddChildView(close_button_); |
| 38 host->AddChildView(maximize_button_); | 45 host->AddChildView(maximize_button_); |
| 39 } | 46 } |
| 40 virtual void Layout(views::View* host) override { | 47 virtual void Layout(views::View* host) override { |
| 41 gfx::Size ps = close_button_->GetPreferredSize(); | 48 gfx::Size ps = capture_checkbox_->GetPreferredSize(); |
| 49 capture_checkbox_->SetBounds(kButtonFrameMargin, kButtonFrameMargin, |
| 50 ps.width(), ps.height()); |
| 51 |
| 52 ps = close_button_->GetPreferredSize(); |
| 42 gfx::Rect bounds = host->GetLocalBounds(); | 53 gfx::Rect bounds = host->GetLocalBounds(); |
| 43 close_button_->SetBounds(bounds.right() - kButtonFrameMargin - ps.width(), | 54 close_button_->SetBounds(bounds.right() - kButtonFrameMargin - ps.width(), |
| 44 kButtonFrameMargin, ps.width(), ps.height()); | 55 kButtonFrameMargin, ps.width(), ps.height()); |
| 45 | 56 |
| 46 ps = maximize_button_->GetPreferredSize(); | 57 ps = maximize_button_->GetPreferredSize(); |
| 47 maximize_button_->SetBounds( | 58 maximize_button_->SetBounds( |
| 48 close_button_->x() - kButtonFrameSpacing - ps.width(), | 59 close_button_->x() - kButtonFrameSpacing - ps.width(), |
| 49 kButtonFrameMargin, ps.width(), ps.height()); | 60 kButtonFrameMargin, ps.width(), ps.height()); |
| 50 | 61 |
| 51 bounds.Inset(kFrameSize, | 62 bounds.Inset(kFrameSize, |
| 52 close_button_->bounds().bottom() + kButtonFrameMargin, | 63 close_button_->bounds().bottom() + kButtonFrameMargin, |
| 53 kFrameSize, kFrameSize); | 64 kFrameSize, kFrameSize); |
| 54 controller_->app_view_->SetBounds(*mojo::Rect::From(bounds)); | 65 controller_->app_view_->SetBounds(*mojo::Rect::From(bounds)); |
| 55 } | 66 } |
| 56 virtual gfx::Size GetPreferredSize(const views::View* host) const override { | 67 virtual gfx::Size GetPreferredSize(const views::View* host) const override { |
| 57 return gfx::Size(); | 68 return gfx::Size(); |
| 58 } | 69 } |
| 59 | 70 |
| 60 // Overridden from views::ButtonListener: | 71 // Overridden from views::ButtonListener: |
| 61 virtual void ButtonPressed(views::Button* sender, | 72 virtual void ButtonPressed(views::Button* sender, |
| 62 const ui::Event& event) override { | 73 const ui::Event& event) override { |
| 63 if (sender == close_button_) | 74 if (sender == close_button_) |
| 64 controller_->CloseWindow(); | 75 controller_->CloseWindow(); |
| 65 else if (sender == maximize_button_) | 76 else if (sender == maximize_button_) |
| 66 controller_->ToggleMaximize(); | 77 controller_->ToggleMaximize(); |
| 78 else if (sender == capture_checkbox_) |
| 79 controller_->SetCapture(capture_checkbox_->checked()); |
| 67 } | 80 } |
| 68 | 81 |
| 69 FrameController* controller_; | 82 FrameController* controller_; |
| 83 views::Checkbox* capture_checkbox_; |
| 70 views::Button* close_button_; | 84 views::Button* close_button_; |
| 71 views::Button* maximize_button_; | 85 views::Button* maximize_button_; |
| 72 | 86 |
| 73 DISALLOW_COPY_AND_ASSIGN(LayoutManager); | 87 DISALLOW_COPY_AND_ASSIGN(LayoutManager); |
| 74 }; | 88 }; |
| 75 | 89 |
| 76 class FrameController::FrameEventHandler : public ui::EventHandler { | 90 class FrameController::FrameEventHandler : public ui::EventHandler { |
| 77 public: | 91 public: |
| 78 explicit FrameEventHandler(FrameController* frame_controller) | 92 explicit FrameEventHandler(FrameController* frame_controller) |
| 79 : frame_controller_(frame_controller) {} | 93 : frame_controller_(frame_controller) {} |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (maximized_) | 153 if (maximized_) |
| 140 view_->SetBounds(view_->parent()->bounds()); | 154 view_->SetBounds(view_->parent()->bounds()); |
| 141 else | 155 else |
| 142 view_->SetBounds(*mojo::Rect::From(restored_bounds_)); | 156 view_->SetBounds(*mojo::Rect::From(restored_bounds_)); |
| 143 } | 157 } |
| 144 | 158 |
| 145 void FrameController::ActivateWindow() { | 159 void FrameController::ActivateWindow() { |
| 146 window_manager_app_->focus_controller()->ActivateView(view_); | 160 window_manager_app_->focus_controller()->ActivateView(view_); |
| 147 } | 161 } |
| 148 | 162 |
| 163 void FrameController::SetCapture(bool frame_has_capture) { |
| 164 if (frame_has_capture) |
| 165 window_manager_app_->capture_controller()->SetCapture(view_); |
| 166 else |
| 167 window_manager_app_->capture_controller()->ReleaseCapture(view_); |
| 168 } |
| 169 |
| 149 //////////////////////////////////////////////////////////////////////////////// | 170 //////////////////////////////////////////////////////////////////////////////// |
| 150 // FrameController, mojo::ViewObserver implementation: | 171 // FrameController, mojo::ViewObserver implementation: |
| 151 | 172 |
| 152 void FrameController::OnViewDestroyed(mojo::View* view) { | 173 void FrameController::OnViewDestroyed(mojo::View* view) { |
| 153 view_->RemoveObserver(this); | 174 view_->RemoveObserver(this); |
| 154 delete this; | 175 delete this; |
| 155 } | 176 } |
| OLD | NEW |