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 "mojo/examples/wm_flow/wm/frame_controller.h" | 5 #include "mojo/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/services/public/cpp/view_manager/view.h" | 10 #include "mojo/services/public/cpp/view_manager/view.h" |
10 #include "mojo/services/window_manager/window_manager_app.h" | 11 #include "mojo/services/window_manager/window_manager_app.h" |
11 #include "mojo/views/native_widget_view_manager.h" | 12 #include "mojo/views/native_widget_view_manager.h" |
12 #include "ui/views/background.h" | 13 #include "ui/views/background.h" |
13 #include "ui/views/controls/button/label_button.h" | 14 #include "ui/views/controls/button/label_button.h" |
14 #include "ui/views/layout/layout_manager.h" | 15 #include "ui/views/layout/layout_manager.h" |
15 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
16 #include "ui/wm/public/activation_client.h" | 17 #include "ui/wm/public/activation_client.h" |
17 | 18 |
18 class FrameController::LayoutManager : public views::LayoutManager, | 19 class FrameController::LayoutManager : public views::LayoutManager, |
(...skipping 24 matching lines...) Expand all Loading... |
43 kButtonFrameMargin, ps.width(), ps.height()); | 44 kButtonFrameMargin, ps.width(), ps.height()); |
44 | 45 |
45 ps = maximize_button_->GetPreferredSize(); | 46 ps = maximize_button_->GetPreferredSize(); |
46 maximize_button_->SetBounds( | 47 maximize_button_->SetBounds( |
47 close_button_->x() - kButtonFrameSpacing - ps.width(), | 48 close_button_->x() - kButtonFrameSpacing - ps.width(), |
48 kButtonFrameMargin, ps.width(), ps.height()); | 49 kButtonFrameMargin, ps.width(), ps.height()); |
49 | 50 |
50 bounds.Inset(kFrameSize, | 51 bounds.Inset(kFrameSize, |
51 close_button_->bounds().bottom() + kButtonFrameMargin, | 52 close_button_->bounds().bottom() + kButtonFrameMargin, |
52 kFrameSize, kFrameSize); | 53 kFrameSize, kFrameSize); |
53 controller_->app_view_->SetBounds(bounds); | 54 controller_->app_view_->SetBounds(*mojo::Rect::From(bounds)); |
54 } | 55 } |
55 virtual gfx::Size GetPreferredSize(const views::View* host) const override { | 56 virtual gfx::Size GetPreferredSize(const views::View* host) const override { |
56 return gfx::Size(); | 57 return gfx::Size(); |
57 } | 58 } |
58 | 59 |
59 // Overridden from views::ButtonListener: | 60 // Overridden from views::ButtonListener: |
60 virtual void ButtonPressed(views::Button* sender, | 61 virtual void ButtonPressed(views::Button* sender, |
61 const ui::Event& event) override { | 62 const ui::Event& event) override { |
62 if (sender == close_button_) | 63 if (sender == close_button_) |
63 controller_->CloseWindow(); | 64 controller_->CloseWindow(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 *app_view = app_view_; | 114 *app_view = app_view_; |
114 frame_view_->set_background( | 115 frame_view_->set_background( |
115 views::Background::CreateSolidBackground(SK_ColorBLUE)); | 116 views::Background::CreateSolidBackground(SK_ColorBLUE)); |
116 frame_view_->SetLayoutManager(frame_view_layout_manager_); | 117 frame_view_->SetLayoutManager(frame_view_layout_manager_); |
117 frame_event_handler_.reset(new FrameEventHandler(this)); | 118 frame_event_handler_.reset(new FrameEventHandler(this)); |
118 frame_view_->AddPreTargetHandler(frame_event_handler_.get()); | 119 frame_view_->AddPreTargetHandler(frame_event_handler_.get()); |
119 views::Widget::InitParams params( | 120 views::Widget::InitParams params( |
120 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 121 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
121 params.native_widget = | 122 params.native_widget = |
122 new mojo::NativeWidgetViewManager(widget_, shell, view_); | 123 new mojo::NativeWidgetViewManager(widget_, shell, view_); |
123 params.bounds = gfx::Rect(view_->bounds().size()); | 124 params.bounds = gfx::Rect( |
| 125 0, 0, view_->bounds().width, view_->bounds().height); |
124 widget_->Init(params); | 126 widget_->Init(params); |
125 widget_->SetContentsView(frame_view_); | 127 widget_->SetContentsView(frame_view_); |
126 widget_->Show(); | 128 widget_->Show(); |
127 } | 129 } |
128 | 130 |
129 FrameController::~FrameController() {} | 131 FrameController::~FrameController() {} |
130 | 132 |
131 void FrameController::CloseWindow() { | 133 void FrameController::CloseWindow() { |
132 app_view_->Destroy(); | 134 app_view_->Destroy(); |
133 view_->Destroy(); | 135 view_->Destroy(); |
134 } | 136 } |
135 | 137 |
136 void FrameController::ToggleMaximize() { | 138 void FrameController::ToggleMaximize() { |
137 if (!maximized_) | 139 if (!maximized_) |
138 restored_bounds_ = view_->bounds(); | 140 restored_bounds_ = view_->bounds().To<gfx::Rect>(); |
139 maximized_ = !maximized_; | 141 maximized_ = !maximized_; |
140 if (maximized_) | 142 if (maximized_) |
141 view_->SetBounds(view_->parent()->bounds()); | 143 view_->SetBounds(view_->parent()->bounds()); |
142 else | 144 else |
143 view_->SetBounds(restored_bounds_); | 145 view_->SetBounds(*mojo::Rect::From(restored_bounds_)); |
144 } | 146 } |
145 | 147 |
146 void FrameController::ActivateWindow() { | 148 void FrameController::ActivateWindow() { |
147 aura::Window* window = window_manager_app_->GetWindowForViewId(view_->id()); | 149 aura::Window* window = window_manager_app_->GetWindowForViewId(view_->id()); |
148 activation_client_->ActivateWindow(window); | 150 activation_client_->ActivateWindow(window); |
149 } | 151 } |
150 | 152 |
151 //////////////////////////////////////////////////////////////////////////////// | 153 //////////////////////////////////////////////////////////////////////////////// |
152 // FrameController, mojo::ViewObserver implementation: | 154 // FrameController, mojo::ViewObserver implementation: |
153 | 155 |
154 void FrameController::OnViewDestroyed(mojo::View* view) { | 156 void FrameController::OnViewDestroyed(mojo::View* view) { |
155 view_->RemoveObserver(this); | 157 view_->RemoveObserver(this); |
156 delete this; | 158 delete this; |
157 } | 159 } |
OLD | NEW |