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

Side by Side Diff: ash/common/frame/custom_frame_view_ash.cc

Issue 2724693002: mash: improves browser frame decorations (Closed)
Patch Set: cleanup Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/frame/custom_frame_view_ash.h" 5 #include "ash/common/frame/custom_frame_view_ash.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h " 10 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h "
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 // View which takes up the entire widget and contains the HeaderView. HeaderView 119 // View which takes up the entire widget and contains the HeaderView. HeaderView
120 // is a child of OverlayView to avoid creating a larger texture than necessary 120 // is a child of OverlayView to avoid creating a larger texture than necessary
121 // when painting the HeaderView to its own layer. 121 // when painting the HeaderView to its own layer.
122 class CustomFrameViewAsh::OverlayView : public views::View, 122 class CustomFrameViewAsh::OverlayView : public views::View,
123 public views::ViewTargeterDelegate { 123 public views::ViewTargeterDelegate {
124 public: 124 public:
125 explicit OverlayView(HeaderView* header_view); 125 explicit OverlayView(HeaderView* header_view);
126 ~OverlayView() override; 126 ~OverlayView() override;
127 127
128 void SetHeaderHeight(base::Optional<int> height);
129
128 // views::View: 130 // views::View:
129 void Layout() override; 131 void Layout() override;
130 132
131 private: 133 private:
132 // views::ViewTargeterDelegate: 134 // views::ViewTargeterDelegate:
133 bool DoesIntersectRect(const views::View* target, 135 bool DoesIntersectRect(const views::View* target,
134 const gfx::Rect& rect) const override; 136 const gfx::Rect& rect) const override;
135 137
136 HeaderView* header_view_; 138 HeaderView* header_view_;
137 139
140 base::Optional<int> header_height_;
James Cook 2017/03/02 21:00:00 This makes sense as Optional.
141
138 DISALLOW_COPY_AND_ASSIGN(OverlayView); 142 DISALLOW_COPY_AND_ASSIGN(OverlayView);
139 }; 143 };
140 144
141 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) 145 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view)
142 : header_view_(header_view) { 146 : header_view_(header_view) {
143 AddChildView(header_view); 147 AddChildView(header_view);
144 SetEventTargeter( 148 SetEventTargeter(
145 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); 149 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
146 } 150 }
147 151
148 CustomFrameViewAsh::OverlayView::~OverlayView() {} 152 CustomFrameViewAsh::OverlayView::~OverlayView() {}
149 153
154 void CustomFrameViewAsh::OverlayView::SetHeaderHeight(
155 base::Optional<int> height) {
156 if (header_height_ == height)
157 return;
158
159 header_height_ = height;
160 Layout();
161 }
162
150 /////////////////////////////////////////////////////////////////////////////// 163 ///////////////////////////////////////////////////////////////////////////////
151 // CustomFrameViewAsh::OverlayView, views::View overrides: 164 // CustomFrameViewAsh::OverlayView, views::View overrides:
152 165
153 void CustomFrameViewAsh::OverlayView::Layout() { 166 void CustomFrameViewAsh::OverlayView::Layout() {
154 // Layout |header_view_| because layout affects the result of 167 // Layout |header_view_| because layout affects the result of
155 // GetPreferredOnScreenHeight(). 168 // GetPreferredOnScreenHeight().
156 header_view_->Layout(); 169 header_view_->Layout();
157 170
158 int onscreen_height = header_view_->GetPreferredOnScreenHeight(); 171 int onscreen_height = header_height_
172 ? *header_height_
173 : header_view_->GetPreferredOnScreenHeight();
159 if (onscreen_height == 0) { 174 if (onscreen_height == 0) {
160 header_view_->SetVisible(false); 175 header_view_->SetVisible(false);
161 } else { 176 } else {
162 int height = header_view_->GetPreferredHeight(); 177 const int height =
178 header_height_ ? *header_height_ : header_view_->GetPreferredHeight();
163 header_view_->SetBounds(0, onscreen_height - height, width(), height); 179 header_view_->SetBounds(0, onscreen_height - height, width(), height);
164 header_view_->SetVisible(true); 180 header_view_->SetVisible(true);
165 } 181 }
166 } 182 }
167 183
168 /////////////////////////////////////////////////////////////////////////////// 184 ///////////////////////////////////////////////////////////////////////////////
169 // CustomFrameViewAsh::OverlayView, views::ViewTargeterDelegate overrides: 185 // CustomFrameViewAsh::OverlayView, views::ViewTargeterDelegate overrides:
170 186
171 bool CustomFrameViewAsh::OverlayView::DoesIntersectRect( 187 bool CustomFrameViewAsh::OverlayView::DoesIntersectRect(
172 const views::View* target, 188 const views::View* target,
173 const gfx::Rect& rect) const { 189 const gfx::Rect& rect) const {
174 CHECK_EQ(target, this); 190 CHECK_EQ(target, this);
175 // Grab events in the header view. Return false for other events so that they 191 // Grab events in the header view. Return false for other events so that they
176 // can be handled by the client view. 192 // can be handled by the client view.
177 return header_view_->HitTestRect(rect); 193 return header_view_->HitTestRect(rect);
178 } 194 }
179 195
180 //////////////////////////////////////////////////////////////////////////////// 196 ////////////////////////////////////////////////////////////////////////////////
181 // CustomFrameViewAsh, public: 197 // CustomFrameViewAsh, public:
182 198
183 // static 199 // static
184 const char CustomFrameViewAsh::kViewClassName[] = "CustomFrameViewAsh"; 200 const char CustomFrameViewAsh::kViewClassName[] = "CustomFrameViewAsh";
185 201
186 CustomFrameViewAsh::CustomFrameViewAsh( 202 CustomFrameViewAsh::CustomFrameViewAsh(
187 views::Widget* frame, 203 views::Widget* frame,
188 ImmersiveFullscreenControllerDelegate* immersive_delegate, 204 ImmersiveFullscreenControllerDelegate* immersive_delegate,
189 bool enable_immersive) 205 bool enable_immersive,
206 mojom::WindowStyle window_style)
190 : frame_(frame), 207 : frame_(frame),
191 header_view_(new HeaderView(frame)), 208 header_view_(new HeaderView(frame, window_style)),
209 overlay_view_(new OverlayView(header_view_)),
192 immersive_delegate_(immersive_delegate ? immersive_delegate 210 immersive_delegate_(immersive_delegate ? immersive_delegate
193 : header_view_) { 211 : header_view_) {
194 WmWindow* frame_window = WmLookup::Get()->GetWindowForWidget(frame); 212 WmWindow* frame_window = WmLookup::Get()->GetWindowForWidget(frame);
195 frame_window->InstallResizeHandleWindowTargeter(nullptr); 213 frame_window->InstallResizeHandleWindowTargeter(nullptr);
196 // |header_view_| is set as the non client view's overlay view so that it can 214 // |header_view_| is set as the non client view's overlay view so that it can
197 // overlay the web contents in immersive fullscreen. 215 // overlay the web contents in immersive fullscreen.
198 frame->non_client_view()->SetOverlayView(new OverlayView(header_view_)); 216 frame->non_client_view()->SetOverlayView(overlay_view_);
199 frame_window->SetColorProperty(WmWindowProperty::TOP_VIEW_COLOR, 217 frame_window->SetColorProperty(WmWindowProperty::TOP_VIEW_COLOR,
200 header_view_->GetInactiveFrameColor()); 218 header_view_->GetInactiveFrameColor());
201 219
202 // A delegate for a more complex way of fullscreening the window may already 220 // A delegate for a more complex way of fullscreening the window may already
203 // be set. This is the case for packaged apps. 221 // be set. This is the case for packaged apps.
204 wm::WindowState* window_state = frame_window->GetWindowState(); 222 wm::WindowState* window_state = frame_window->GetWindowState();
205 if (!window_state->HasDelegate()) { 223 if (!window_state->HasDelegate()) {
206 window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>( 224 window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>(
207 new CustomFrameViewAshWindowStateDelegate(window_state, this, 225 new CustomFrameViewAshWindowStateDelegate(window_state, this,
208 enable_immersive))); 226 enable_immersive)));
209 } 227 }
210 } 228 }
211 229
212 CustomFrameViewAsh::~CustomFrameViewAsh() {} 230 CustomFrameViewAsh::~CustomFrameViewAsh() {}
213 231
214 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( 232 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView(
215 ImmersiveFullscreenController* immersive_fullscreen_controller) { 233 ImmersiveFullscreenController* immersive_fullscreen_controller) {
216 immersive_fullscreen_controller->Init(immersive_delegate_, frame_, 234 immersive_fullscreen_controller->Init(immersive_delegate_, frame_,
217 header_view_); 235 header_view_);
218 } 236 }
219 237
220 void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, 238 void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color,
221 SkColor inactive_frame_color) { 239 SkColor inactive_frame_color) {
222 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); 240 header_view_->SetFrameColors(active_frame_color, inactive_frame_color);
223 WmWindow* frame_window = WmLookup::Get()->GetWindowForWidget(frame_); 241 WmWindow* frame_window = WmLookup::Get()->GetWindowForWidget(frame_);
224 frame_window->SetColorProperty(WmWindowProperty::TOP_VIEW_COLOR, 242 frame_window->SetColorProperty(WmWindowProperty::TOP_VIEW_COLOR,
225 header_view_->GetInactiveFrameColor()); 243 header_view_->GetInactiveFrameColor());
226 } 244 }
227 245
246 void CustomFrameViewAsh::SetHeaderHeight(base::Optional<int> height) {
247 overlay_view_->SetHeaderHeight(height);
248 }
249
228 //////////////////////////////////////////////////////////////////////////////// 250 ////////////////////////////////////////////////////////////////////////////////
229 // CustomFrameViewAsh, views::NonClientFrameView overrides: 251 // CustomFrameViewAsh, views::NonClientFrameView overrides:
230 252
231 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { 253 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const {
232 gfx::Rect client_bounds = bounds(); 254 gfx::Rect client_bounds = bounds();
233 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); 255 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0);
234 return client_bounds; 256 return client_bounds;
235 } 257 }
236 258
237 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( 259 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 FrameCaptionButtonContainerView* 376 FrameCaptionButtonContainerView*
355 CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() { 377 CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() {
356 return header_view_->caption_button_container(); 378 return header_view_->caption_button_container();
357 } 379 }
358 380
359 int CustomFrameViewAsh::NonClientTopBorderHeight() const { 381 int CustomFrameViewAsh::NonClientTopBorderHeight() const {
360 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); 382 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight();
361 } 383 }
362 384
363 } // namespace ash 385 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698