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

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

Issue 2227643003: Converts mash to use the common non-client frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@native_widget_mus_fix
Patch Set: tweaks Created 4 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "ash/mus/non_client_frame_controller.h" 5 #include "ash/mus/non_client_frame_controller.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/common/ash_constants.h"
14 #include "ash/common/ash_layout_constants.h"
15 #include "ash/common/frame/custom_frame_view_ash.h"
13 #include "ash/mus/bridge/wm_window_mus.h" 16 #include "ash/mus/bridge/wm_window_mus.h"
14 #include "ash/mus/frame/frame_border_hit_test_controller.h" 17 #include "ash/mus/move_event_handler.h"
15 #include "ash/mus/frame/move_event_handler.h"
16 #include "ash/mus/frame/non_client_frame_view_mash.h"
17 #include "ash/mus/property_util.h" 18 #include "ash/mus/property_util.h"
18 #include "ash/mus/shadow.h" 19 #include "ash/mus/shadow.h"
19 #include "base/macros.h" 20 #include "base/macros.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "services/ui/public/cpp/property_type_converters.h" 22 #include "services/ui/public/cpp/property_type_converters.h"
22 #include "services/ui/public/cpp/window.h" 23 #include "services/ui/public/cpp/window.h"
23 #include "services/ui/public/cpp/window_manager_delegate.h" 24 #include "services/ui/public/cpp/window_manager_delegate.h"
24 #include "services/ui/public/cpp/window_property.h" 25 #include "services/ui/public/cpp/window_property.h"
25 #include "services/ui/public/interfaces/window_manager.mojom.h" 26 #include "services/ui/public/interfaces/window_manager.mojom.h"
26 #include "services/ui/public/interfaces/window_tree_host.mojom.h" 27 #include "services/ui/public/interfaces/window_tree_host.mojom.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 : NativeWidgetMus(delegate, window, ui::mojom::SurfaceType::UNDERLAY), 118 : NativeWidgetMus(delegate, window, ui::mojom::SurfaceType::UNDERLAY),
118 window_manager_client_(window_manager_client) {} 119 window_manager_client_(window_manager_client) {}
119 ~WmNativeWidgetMus() override {} 120 ~WmNativeWidgetMus() override {}
120 121
121 // NativeWidgetMus: 122 // NativeWidgetMus:
122 views::NonClientFrameView* CreateNonClientFrameView() override { 123 views::NonClientFrameView* CreateNonClientFrameView() override {
123 move_event_handler_.reset(new MoveEventHandler( 124 move_event_handler_.reset(new MoveEventHandler(
124 window(), window_manager_client_, GetNativeView())); 125 window(), window_manager_client_, GetNativeView()));
125 if (ShouldRemoveStandardFrame(window())) 126 if (ShouldRemoveStandardFrame(window()))
126 return new EmptyDraggableNonClientFrameView(); 127 return new EmptyDraggableNonClientFrameView();
127 return new NonClientFrameViewMash(GetWidget(), window()); 128 return new CustomFrameViewAsh(GetWidget());
128 } 129 }
129 void InitNativeWidget(const views::Widget::InitParams& params) override { 130 void InitNativeWidget(const views::Widget::InitParams& params) override {
130 views::NativeWidgetMus::InitNativeWidget(params); 131 views::NativeWidgetMus::InitNativeWidget(params);
131 aura::WindowTreeHost* window_tree_host = GetNativeView()->GetHost(); 132 aura::WindowTreeHost* window_tree_host = GetNativeView()->GetHost();
132 // TODO(sky): shadow should be determined by window type and shadow type. 133 // TODO(sky): shadow should be determined by window type and shadow type.
133 shadow_.reset(new Shadow); 134 shadow_.reset(new Shadow);
134 shadow_->Init(Shadow::STYLE_INACTIVE); 135 shadow_->Init(Shadow::STYLE_INACTIVE);
135 shadow_->Install(window()); 136 shadow_->Install(window());
136 ContentWindowLayoutManager* layout_manager = new ContentWindowLayoutManager( 137 ContentWindowLayoutManager* layout_manager = new ContentWindowLayoutManager(
137 window_tree_host->window(), shadow_.get()); 138 window_tree_host->window(), shadow_.get());
138 window_tree_host->window()->SetLayoutManager(layout_manager); 139 window_tree_host->window()->SetLayoutManager(layout_manager);
139 const int inset = Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE); 140 const int inset = Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE);
140 window_tree_host->SetOutputSurfacePadding( 141 window_tree_host->SetOutputSurfacePadding(
141 gfx::Insets(inset, inset, inset, inset)); 142 gfx::Insets(inset, inset, inset, inset));
142 window_tree_host->window()->layer()->Add(shadow_->layer()); 143 window_tree_host->window()->layer()->Add(shadow_->layer());
143 shadow_->layer()->parent()->StackAtBottom(shadow_->layer()); 144 shadow_->layer()->parent()->StackAtBottom(shadow_->layer());
144 } 145 }
145 void CenterWindow(const gfx::Size& size) override {
sky 2016/08/08 23:32:27 These overrides are no longer necessary because of
James Cook 2016/08/09 00:37:10 Hooray! No more tricky empty overrides.
146 // Do nothing. The client controls the size, not us.
147 }
148 bool SetWindowTitle(const base::string16& title) override {
149 // Do nothing. The client controls the window title, not us.
150 return false;
151 }
152 void SetWindowIcons(const gfx::ImageSkia& window_icon,
153 const gfx::ImageSkia& app_icon) override {
154 // Do nothing. The client controls window icons, not us.
155 }
156 void UpdateClientArea() override {
157 // This pushes the client area to the WS. We don't want to do that as
158 // the client area should come from the client, not us.
159 }
160 146
161 private: 147 private:
162 // The shadow, may be null. 148 // The shadow, may be null.
163 std::unique_ptr<Shadow> shadow_; 149 std::unique_ptr<Shadow> shadow_;
164 150
165 std::unique_ptr<MoveEventHandler> move_event_handler_; 151 std::unique_ptr<MoveEventHandler> move_event_handler_;
166 152
167 ui::WindowManagerClient* window_manager_client_; 153 ui::WindowManagerClient* window_manager_client_;
168 154
169 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetMus); 155 DISALLOW_COPY_AND_ASSIGN(WmNativeWidgetMus);
(...skipping 16 matching lines...) Expand all
186 frame_controller_->window()->RequestClose(); 172 frame_controller_->window()->RequestClose();
187 return false; 173 return false;
188 } 174 }
189 175
190 private: 176 private:
191 NonClientFrameController* frame_controller_; 177 NonClientFrameController* frame_controller_;
192 178
193 DISALLOW_COPY_AND_ASSIGN(ClientViewMus); 179 DISALLOW_COPY_AND_ASSIGN(ClientViewMus);
194 }; 180 };
195 181
182 // Returns the frame insets to use when ShouldUseExtendedHitRegion() returns
183 // true.
184 gfx::Insets GetExtendedHitRegion() {
185 return gfx::Insets(kResizeOutsideBoundsSize, kResizeOutsideBoundsSize,
186 kResizeOutsideBoundsSize, kResizeOutsideBoundsSize);
187 }
188
196 } // namespace 189 } // namespace
197 190
198 // static 191 // static
199 void NonClientFrameController::Create( 192 void NonClientFrameController::Create(
200 shell::Connector* connector, 193 shell::Connector* connector,
201 ui::Window* parent, 194 ui::Window* parent,
202 ui::Window* window, 195 ui::Window* window,
203 ui::WindowManagerClient* window_manager_client) { 196 ui::WindowManagerClient* window_manager_client) {
204 new NonClientFrameController(connector, parent, window, 197 new NonClientFrameController(connector, parent, window,
205 window_manager_client); 198 window_manager_client);
206 } 199 }
207 200
208 // static 201 // static
209 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() { 202 gfx::Insets NonClientFrameController::GetPreferredClientAreaInsets() {
210 return NonClientFrameViewMash::GetPreferredClientAreaInsets(); 203 // TODO(sky): figure out a better way to get this rather than hard coding.
204 // This value comes from the header (see DefaultHeaderPainter::LayoutHeader,
205 // which uses the preferred height of the CaptionButtonContainer, which uses
206 // the height of the close button).
207 return gfx::Insets(
208 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).height(), 0,
209 0, 0);
211 } 210 }
212 211
213 // static 212 // static
214 int NonClientFrameController::GetMaxTitleBarButtonWidth() { 213 int NonClientFrameController::GetMaxTitleBarButtonWidth() {
215 return NonClientFrameViewMash::GetMaxTitleBarButtonWidth(); 214 // TODO(sky): same comment as for GetPreferredClientAreaInsets().
215 return GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).width() *
216 3;
216 } 217 }
217 218
218 NonClientFrameController::NonClientFrameController( 219 NonClientFrameController::NonClientFrameController(
219 shell::Connector* connector, 220 shell::Connector* connector,
220 ui::Window* parent, 221 ui::Window* parent,
221 ui::Window* window, 222 ui::Window* window,
222 ui::WindowManagerClient* window_manager_client) 223 ui::WindowManagerClient* window_manager_client)
223 : widget_(new views::Widget), window_(window) { 224 : widget_(new views::Widget), window_(window) {
224 WmWindowMus* wm_window = WmWindowMus::Get(window); 225 WmWindowMus* wm_window = WmWindowMus::Get(window);
225 wm_window->set_widget(widget_, WmWindowMus::WidgetCreationType::FOR_CLIENT); 226 wm_window->set_widget(widget_, WmWindowMus::WidgetCreationType::FOR_CLIENT);
(...skipping 11 matching lines...) Expand all
237 new WmNativeWidgetMus(widget_, window, window_manager_client); 238 new WmNativeWidgetMus(widget_, window, window_manager_client);
238 widget_->Init(params); 239 widget_->Init(params);
239 240
240 parent->AddChild(window); 241 parent->AddChild(window);
241 242
242 widget_->ShowInactive(); 243 widget_->ShowInactive();
243 244
244 const int shadow_inset = 245 const int shadow_inset =
245 Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE); 246 Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE);
246 const gfx::Insets extended_hit_region = 247 const gfx::Insets extended_hit_region =
247 wm_window->ShouldUseExtendedHitRegion() 248 wm_window->ShouldUseExtendedHitRegion() ? GetExtendedHitRegion()
248 ? FrameBorderHitTestController::GetResizeOutsideBoundsSize() 249 : gfx::Insets();
249 : gfx::Insets();
250 window_manager_client->SetUnderlaySurfaceOffsetAndExtendedHitArea( 250 window_manager_client->SetUnderlaySurfaceOffsetAndExtendedHitArea(
251 window, gfx::Vector2d(shadow_inset, shadow_inset), extended_hit_region); 251 window, gfx::Vector2d(shadow_inset, shadow_inset), extended_hit_region);
252 } 252 }
253 253
254 NonClientFrameController::~NonClientFrameController() { 254 NonClientFrameController::~NonClientFrameController() {
255 if (window_) 255 if (window_)
256 window_->RemoveObserver(this); 256 window_->RemoveObserver(this);
257 } 257 }
258 258
259 base::string16 NonClientFrameController::GetWindowTitle() const { 259 base::string16 NonClientFrameController::GetWindowTitle() const {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 324 }
325 } 325 }
326 326
327 void NonClientFrameController::OnWindowDestroyed(ui::Window* window) { 327 void NonClientFrameController::OnWindowDestroyed(ui::Window* window) {
328 window_->RemoveObserver(this); 328 window_->RemoveObserver(this);
329 window_ = nullptr; 329 window_ = nullptr;
330 } 330 }
331 331
332 } // namespace mus 332 } // namespace mus
333 } // namespace ash 333 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698