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

Side by Side Diff: ash/mus/wm/non_client_frame_controller.cc

Issue 1641003002: [exp] ash: Ash in Mus. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tot-merge Created 4 years, 10 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 | « ash/mus/wm/non_client_frame_controller.h ('k') | ash/mus/wm/window_manager_application.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/mus/wm/non_client_frame_controller.h"
6
7 #include <stdint.h>
8
9 #include "base/macros.h"
10 #include "components/mus/public/cpp/property_type_converters.h"
11 #include "components/mus/public/cpp/window.h"
12 #include "components/mus/public/cpp/window_property.h"
13 #include "components/mus/public/interfaces/window_manager.mojom.h"
14 #include "components/mus/public/interfaces/window_tree_host.mojom.h"
15 #include "mojo/converters/geometry/geometry_type_converters.h"
16 #include "ui/aura/layout_manager.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_tree_host.h"
19 #include "ui/compositor/layer.h"
20 #include "ui/views/mus/native_widget_mus.h"
21 #include "ui/views/mus/platform_window_mus.h"
22 #include "ui/views/widget/native_widget_aura.h"
23 #include "ui/views/widget/widget.h"
24 #include "ui/views/widget/widget_observer.h"
25
26 namespace ash {
27 namespace muswm {
28 namespace {
29
30 void SatisfyCallback(cc::SurfaceSequence sequence) {
31 // TODO(fsamuel): Implement this.
32 }
33
34 // See surface_layer.h for a description of this callback.
35 void RequireCallback(cc::SurfaceId surface_id, cc::SurfaceSequence sequence) {
36 // TODO(fsamuel): Implement this.
37 }
38
39 const int kCaptionHeight = 33;
40
41 class NSync : public views::WidgetObserver, public ui::PlatformWindowDelegate {
42 public:
43 NSync(views::Widget* widget, mojo::Shell* shell, mus::Window* window)
44 : widget_(widget),
45 platform_window_(new views::PlatformWindowMus(this, shell, window)),
46 mus_window_(window) {
47 widget_->AddObserver(this);
48 CreateLayer();
49 }
50
51 ~NSync() override {
52 if (widget_)
53 widget_->RemoveObserver(this);
54 }
55
56 private:
57 void CreateLayer() {
58 DCHECK(widget_);
59 layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
60 UpdateLayerSize();
61 layer_->SetVisible(true);
62 widget_->GetNativeWindow()->layer()->Add(layer_.get());
63 }
64
65 void UpdateLayerSize() {
66 gfx::Rect bounds(platform_window_->GetBounds());
67 layer_->SetBounds(gfx::Rect(gfx::Point(0, kCaptionHeight), bounds.size()));
68 layer_->SetShowSurface(static_cast<cc::SurfaceId>(mus_window_->id()),
69 base::Bind(&SatisfyCallback),
70 base::Bind(&RequireCallback), bounds.size(),
71 1.f, // XXX(sad):
72 bounds.size());
73 }
74
75 // views::WidgetObserver:
76 void OnWidgetDestroying(views::Widget* widget) override {
77 widget_->RemoveObserver(this);
78 widget_ = nullptr;
79 mus_window_->RequestClose();
80 }
81
82 void OnWidgetBoundsChanged(views::Widget* widget,
83 const gfx::Rect& bounds) override {
84 gfx::Rect newbounds = bounds;
85 newbounds.set_height(bounds.height() - kCaptionHeight);
86 platform_window_->SetBounds(newbounds);
87 UpdateLayerSize();
88 }
89
90 // ui::PlatformWindowDelegate:
91 void OnBoundsChanged(const gfx::Rect& new_bounds) override {}
92 void OnDamageRect(const gfx::Rect& damaged_region) override {}
93 void DispatchEvent(ui::Event* event) override {}
94 void OnCloseRequest() override {}
95 void OnClosed() override { delete this; }
96 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
97 void OnLostCapture() override {}
98 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
99 float device_pixel_ratio) override {}
100 void OnAcceleratedWidgetDestroyed() override {}
101 void OnActivationChanged(bool active) override {}
102
103 views::Widget* widget_;
104 scoped_ptr<views::PlatformWindowMus> platform_window_;
105 scoped_ptr<ui::Layer> layer_;
106 mus::Window* mus_window_;
107
108 DISALLOW_COPY_AND_ASSIGN(NSync);
109 };
110
111 } // namespace
112
113 NonClientFrameController::NonClientFrameController(
114 mojo::Shell* shell,
115 mus::Window* window,
116 mus::mojom::WindowTreeHost* window_tree_host,
117 aura::Window* aura_root)
118 : widget_(new views::Widget),
119 window_(window),
120 mus_window_tree_host_(window_tree_host) {
121 window_->AddObserver(this);
122
123 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
124 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES;
125 params.delegate = this;
126 params.native_widget = new views::NativeWidgetAura(widget_);
127 params.context = aura_root;
128 params.bounds = window_->bounds();
129 widget_->Init(params);
130 widget_->Show();
131 widget_->GetNativeWindow()->SetName(__PRETTY_FUNCTION__);
132
133 new NSync(widget_, shell, window_);
134 }
135
136 NonClientFrameController::~NonClientFrameController() {
137 if (window_)
138 window_->RemoveObserver(this);
139 }
140
141 base::string16 NonClientFrameController::GetWindowTitle() const {
142 if (!window_ ||
143 !window_->HasSharedProperty(
144 mus::mojom::WindowManager::kWindowTitle_Property)) {
145 return base::string16();
146 }
147
148 return window_->GetSharedProperty<base::string16>(
149 mus::mojom::WindowManager::kWindowTitle_Property);
150 }
151
152 views::View* NonClientFrameController::GetContentsView() {
153 return this;
154 }
155
156 bool NonClientFrameController::CanResize() const {
157 return true;
158 }
159
160 bool NonClientFrameController::CanMaximize() const {
161 return true;
162 }
163
164 bool NonClientFrameController::CanMinimize() const {
165 return true;
166 }
167
168 void NonClientFrameController::OnWindowSharedPropertyChanged(
169 mus::Window* window,
170 const std::string& name,
171 const std::vector<uint8_t>* old_data,
172 const std::vector<uint8_t>* new_data) {
173 if (name == mus::mojom::WindowManager::kResizeBehavior_Property)
174 widget_->OnSizeConstraintsChanged();
175 else if (name == mus::mojom::WindowManager::kWindowTitle_Property)
176 widget_->UpdateWindowTitle();
177 }
178
179 void NonClientFrameController::OnWindowDestroyed(mus::Window* window) {
180 window_->RemoveObserver(this);
181 window_ = nullptr;
182 }
183
184 } // namespace muswm
185 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/wm/non_client_frame_controller.h ('k') | ash/mus/wm/window_manager_application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698