Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: mojo/examples/wm_flow/wm/frame_controller.cc

Issue 599213002: First cut at supporting activation in the window manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: / Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/examples/wm_flow/wm/frame_controller.h ('k') | mojo/examples/wm_flow/wm/wm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "mojo/services/public/cpp/view_manager/view.h" 8 #include "mojo/services/public/cpp/view_manager/view.h"
9 #include "mojo/services/window_manager/window_manager_app.h"
9 #include "mojo/views/native_widget_view_manager.h" 10 #include "mojo/views/native_widget_view_manager.h"
10 #include "ui/views/background.h" 11 #include "ui/views/background.h"
11 #include "ui/views/controls/button/label_button.h" 12 #include "ui/views/controls/button/label_button.h"
12 #include "ui/views/layout/layout_manager.h" 13 #include "ui/views/layout/layout_manager.h"
13 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
15 #include "ui/wm/public/activation_client.h"
14 16
15 class FrameController::LayoutManager : public views::LayoutManager, 17 class FrameController::LayoutManager : public views::LayoutManager,
16 public views::ButtonListener { 18 public views::ButtonListener {
17 public: 19 public:
18 explicit LayoutManager(FrameController* controller) 20 explicit LayoutManager(FrameController* controller)
19 : controller_(controller), 21 : controller_(controller),
20 close_button_( 22 close_button_(
21 new views::LabelButton(this, base::ASCIIToUTF16("Begone"))), 23 new views::LabelButton(this, base::ASCIIToUTF16("Begone"))),
22 maximize_button_( 24 maximize_button_(
23 new views::LabelButton(this, base::ASCIIToUTF16("Embiggen"))) {} 25 new views::LabelButton(this, base::ASCIIToUTF16("Embiggen"))) {}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 controller_->ToggleMaximize(); 64 controller_->ToggleMaximize();
63 } 65 }
64 66
65 FrameController* controller_; 67 FrameController* controller_;
66 views::Button* close_button_; 68 views::Button* close_button_;
67 views::Button* maximize_button_; 69 views::Button* maximize_button_;
68 70
69 DISALLOW_COPY_AND_ASSIGN(LayoutManager); 71 DISALLOW_COPY_AND_ASSIGN(LayoutManager);
70 }; 72 };
71 73
74 class FrameController::FrameEventHandler : public ui::EventHandler {
75 public:
76 explicit FrameEventHandler(FrameController* frame_controller)
77 : frame_controller_(frame_controller) {}
78 virtual ~FrameEventHandler() {}
79
80 private:
81
82 // Overriden from ui::EventHandler:
83 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
84 if (event->type() == ui::ET_MOUSE_PRESSED)
85 frame_controller_->ActivateWindow();
86 }
87
88 FrameController* frame_controller_;
89
90 DISALLOW_COPY_AND_ASSIGN(FrameEventHandler);
91 };
92
72 //////////////////////////////////////////////////////////////////////////////// 93 ////////////////////////////////////////////////////////////////////////////////
73 // FrameController, public: 94 // FrameController, public:
74 95
75 FrameController::FrameController(mojo::View* view, mojo::View** app_view) 96 FrameController::FrameController(
97 mojo::View* view,
98 mojo::View** app_view,
99 aura::client::ActivationClient* activation_client,
100 mojo::WindowManagerApp* window_manager_app)
76 : view_(view), 101 : view_(view),
77 app_view_(mojo::View::Create(view->view_manager())), 102 app_view_(mojo::View::Create(view->view_manager())),
78 frame_view_(new views::View), 103 frame_view_(new views::View),
79 frame_view_layout_manager_(new LayoutManager(this)), 104 frame_view_layout_manager_(new LayoutManager(this)),
80 widget_(new views::Widget), 105 widget_(new views::Widget),
81 maximized_(false) { 106 maximized_(false),
107 activation_client_(activation_client),
108 window_manager_app_(window_manager_app) {
82 view_->AddChild(app_view_); 109 view_->AddChild(app_view_);
83 view_->AddObserver(this); 110 view_->AddObserver(this);
84 *app_view = app_view_; 111 *app_view = app_view_;
85 frame_view_->set_background( 112 frame_view_->set_background(
86 views::Background::CreateSolidBackground(SK_ColorBLUE)); 113 views::Background::CreateSolidBackground(SK_ColorBLUE));
87 frame_view_->SetLayoutManager(frame_view_layout_manager_); 114 frame_view_->SetLayoutManager(frame_view_layout_manager_);
115 frame_event_handler_.reset(new FrameEventHandler(this));
116 frame_view_->AddPreTargetHandler(frame_event_handler_.get());
88 views::Widget::InitParams params( 117 views::Widget::InitParams params(
89 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 118 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
90 params.native_widget = new mojo::NativeWidgetViewManager(widget_, view_); 119 params.native_widget = new mojo::NativeWidgetViewManager(widget_, view_);
91 params.bounds = gfx::Rect(view_->bounds().size()); 120 params.bounds = gfx::Rect(view_->bounds().size());
92 widget_->Init(params); 121 widget_->Init(params);
93 widget_->SetContentsView(frame_view_); 122 widget_->SetContentsView(frame_view_);
94 widget_->Show(); 123 widget_->Show();
95 } 124 }
96 125
97 FrameController::~FrameController() {} 126 FrameController::~FrameController() {}
98 127
99 void FrameController::CloseWindow() { 128 void FrameController::CloseWindow() {
100 app_view_->Destroy(); 129 app_view_->Destroy();
101 view_->Destroy(); 130 view_->Destroy();
102 } 131 }
103 132
104 void FrameController::ToggleMaximize() { 133 void FrameController::ToggleMaximize() {
105 if (!maximized_) 134 if (!maximized_)
106 restored_bounds_ = view_->bounds(); 135 restored_bounds_ = view_->bounds();
107 maximized_ = !maximized_; 136 maximized_ = !maximized_;
108 if (maximized_) 137 if (maximized_)
109 view_->SetBounds(view_->parent()->bounds()); 138 view_->SetBounds(view_->parent()->bounds());
110 else 139 else
111 view_->SetBounds(restored_bounds_); 140 view_->SetBounds(restored_bounds_);
112 } 141 }
113 142
143 void FrameController::ActivateWindow() {
144 aura::Window* window = window_manager_app_->GetWindowForViewId(view_->id());
145 activation_client_->ActivateWindow(window);
146 }
147
114 //////////////////////////////////////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////////////////
115 // FrameController, mojo::ViewObserver implementation: 149 // FrameController, mojo::ViewObserver implementation:
116 150
117 void FrameController::OnViewDestroyed(mojo::View* view) { 151 void FrameController::OnViewDestroyed(mojo::View* view) {
118 view_->RemoveObserver(this); 152 view_->RemoveObserver(this);
119 delete this; 153 delete this;
120 } 154 }
OLDNEW
« no previous file with comments | « mojo/examples/wm_flow/wm/frame_controller.h ('k') | mojo/examples/wm_flow/wm/wm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698