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

Side by Side Diff: mash/wm/frame/non_client_frame_view_mash.cc

Issue 1459653002: Gets mustash frames looking like that of ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update test Created 5 years, 1 month 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 | « mash/wm/frame/non_client_frame_view_mash.h ('k') | mash/wm/move_loop.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 "mash/wm/frame/non_client_frame_view_mash.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "components/mus/public/cpp/window.h"
11 #include "grit/mash_wm_resources.h"
12 #include "mash/wm/frame/caption_buttons/frame_caption_button_container_view.h"
13 #include "mash/wm/frame/default_header_painter.h"
14 #include "mash/wm/frame/frame_border_hit_test_controller.h"
15 #include "mash/wm/frame/header_painter.h"
16 #include "mash/wm/frame/move_loop.h"
17 #include "mojo/converters/input_events/input_events_type_converters.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/compositor/paint_recorder.h"
20 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/geometry/rect_conversions.h"
23 #include "ui/gfx/geometry/size.h"
24 #include "ui/gfx/image/image.h"
25 #include "ui/views/view.h"
26 #include "ui/views/widget/widget.h"
27 #include "ui/views/widget/widget_delegate.h"
28
29 namespace mash {
30 namespace wm {
31
32 ///////////////////////////////////////////////////////////////////////////////
33 // NonClientFrameViewMash::HeaderView
34
35 // View which paints the header.
36 class NonClientFrameViewMash::HeaderView : public views::View {
37 public:
38 // |frame| is the widget that the caption buttons act on.
39 explicit HeaderView(views::Widget* frame);
40 ~HeaderView() override;
41
42 // Schedules a repaint for the entire title.
43 void SchedulePaintForTitle();
44
45 // Tells the window controls to reset themselves to the normal state.
46 void ResetWindowControls();
47
48 // Returns the view's preferred height.
49 int GetPreferredHeight() const;
50
51 // Returns the view's minimum width.
52 int GetMinimumWidth() const;
53
54 void SizeConstraintsChanged();
55
56 void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color);
57
58 // views::View:
59 void Layout() override;
60 void OnPaint(gfx::Canvas* canvas) override;
61 void ChildPreferredSizeChanged(views::View* child) override;
62
63 FrameCaptionButtonContainerView* caption_button_container() {
64 return caption_button_container_;
65 }
66
67 private:
68 // The widget that the caption buttons act on.
69 views::Widget* frame_;
70
71 // Helper for painting the header.
72 scoped_ptr<DefaultHeaderPainter> header_painter_;
73
74 // View which contains the window caption buttons.
75 FrameCaptionButtonContainerView* caption_button_container_;
76
77 DISALLOW_COPY_AND_ASSIGN(HeaderView);
78 };
79
80 NonClientFrameViewMash::HeaderView::HeaderView(views::Widget* frame)
81 : frame_(frame),
82 header_painter_(new DefaultHeaderPainter),
83 caption_button_container_(nullptr) {
84 caption_button_container_ = new FrameCaptionButtonContainerView(frame_);
85 caption_button_container_->UpdateSizeButtonVisibility();
86 AddChildView(caption_button_container_);
87
88 header_painter_->Init(frame_, this, caption_button_container_);
89 }
90
91 NonClientFrameViewMash::HeaderView::~HeaderView() {}
92
93 void NonClientFrameViewMash::HeaderView::SchedulePaintForTitle() {
94 header_painter_->SchedulePaintForTitle();
95 }
96
97 void NonClientFrameViewMash::HeaderView::ResetWindowControls() {
98 caption_button_container_->ResetWindowControls();
99 }
100
101 int NonClientFrameViewMash::HeaderView::GetPreferredHeight() const {
102 return header_painter_->GetHeaderHeightForPainting();
103 }
104
105 int NonClientFrameViewMash::HeaderView::GetMinimumWidth() const {
106 return header_painter_->GetMinimumHeaderWidth();
107 }
108
109 void NonClientFrameViewMash::HeaderView::SizeConstraintsChanged() {
110 caption_button_container_->ResetWindowControls();
111 caption_button_container_->UpdateSizeButtonVisibility();
112 Layout();
113 }
114
115 void NonClientFrameViewMash::HeaderView::SetFrameColors(
116 SkColor active_frame_color,
117 SkColor inactive_frame_color) {
118 header_painter_->SetFrameColors(active_frame_color, inactive_frame_color);
119 }
120
121 ///////////////////////////////////////////////////////////////////////////////
122 // NonClientFrameViewMash::HeaderView, views::View overrides:
123
124 void NonClientFrameViewMash::HeaderView::Layout() {
125 header_painter_->LayoutHeader();
126 }
127
128 void NonClientFrameViewMash::HeaderView::OnPaint(gfx::Canvas* canvas) {
129 bool paint_as_active =
130 frame_->non_client_view()->frame_view()->ShouldPaintAsActive();
131 caption_button_container_->SetPaintAsActive(paint_as_active);
132
133 HeaderPainter::Mode header_mode = paint_as_active
134 ? HeaderPainter::MODE_ACTIVE
135 : HeaderPainter::MODE_INACTIVE;
136 header_painter_->PaintHeader(canvas, header_mode);
137 }
138
139 void NonClientFrameViewMash::HeaderView::ChildPreferredSizeChanged(
140 views::View* child) {
141 // FrameCaptionButtonContainerView animates the visibility changes in
142 // UpdateSizeButtonVisibility(false). Due to this a new size is not available
143 // until the completion of the animation. Layout in response to the preferred
144 // size changes.
145 if (child != caption_button_container_)
146 return;
147 parent()->Layout();
148 }
149
150 ////////////////////////////////////////////////////////////////////////////////
151 // NonClientFrameViewMash, public:
152
153 // static
154 const char NonClientFrameViewMash::kViewClassName[] = "NonClientFrameViewMash";
155
156 NonClientFrameViewMash::NonClientFrameViewMash(views::Widget* frame,
157 mus::Window* window)
158 : frame_(frame), window_(window), header_view_(new HeaderView(frame)) {
159 // |header_view_| is set as the non client view's overlay view so that it can
160 // overlay the web contents in immersive fullscreen.
161 AddChildView(header_view_);
162 window_->AddObserver(this);
163 }
164
165 NonClientFrameViewMash::~NonClientFrameViewMash() {
166 if (window_)
167 window_->RemoveObserver(this);
168 }
169
170 // static
171 gfx::Insets NonClientFrameViewMash::GetPreferredClientAreaInsets() {
172 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
173 const int header_height =
174 rb.GetImageSkiaNamed(IDR_MASH_WM_WINDOW_CONTROL_BACKGROUND_P)
175 ->size()
176 .height();
177 return gfx::Insets(header_height, 0, 0, 0);
178 }
179
180 void NonClientFrameViewMash::SetFrameColors(SkColor active_frame_color,
181 SkColor inactive_frame_color) {
182 header_view_->SetFrameColors(active_frame_color, inactive_frame_color);
183 }
184
185 ////////////////////////////////////////////////////////////////////////////////
186 // NonClientFrameViewMash, views::NonClientFrameView overrides:
187
188 gfx::Rect NonClientFrameViewMash::GetBoundsForClientView() const {
189 gfx::Rect result(GetLocalBounds());
190 result.Inset(window_->client_area());
191 return result;
192 }
193
194 gfx::Rect NonClientFrameViewMash::GetWindowBoundsForClientBounds(
195 const gfx::Rect& client_bounds) const {
196 gfx::Rect window_bounds = client_bounds;
197 window_bounds.Inset(
198 window_->client_area().left(), window_->client_area().top(),
199 window_->client_area().right(), window_->client_area().bottom());
200 return window_bounds;
201 }
202
203 int NonClientFrameViewMash::NonClientHitTest(const gfx::Point& point) {
204 return FrameBorderHitTestController::NonClientHitTest(
205 this, header_view_->caption_button_container(), point);
206 }
207
208 void NonClientFrameViewMash::GetWindowMask(const gfx::Size& size,
209 gfx::Path* window_mask) {}
210
211 void NonClientFrameViewMash::ResetWindowControls() {
212 header_view_->ResetWindowControls();
213 }
214
215 void NonClientFrameViewMash::UpdateWindowIcon() {}
216
217 void NonClientFrameViewMash::UpdateWindowTitle() {
218 header_view_->SchedulePaintForTitle();
219 }
220
221 void NonClientFrameViewMash::SizeConstraintsChanged() {
222 header_view_->SizeConstraintsChanged();
223 }
224
225 ////////////////////////////////////////////////////////////////////////////////
226 // NonClientFrameViewMash, views::View overrides:
227
228 void NonClientFrameViewMash::Layout() {
229 header_view_->SetBounds(0, 0, width(), header_view_->GetPreferredHeight());
230 header_view_->Layout();
231 }
232
233 gfx::Size NonClientFrameViewMash::GetPreferredSize() const {
234 gfx::Size pref = frame_->client_view()->GetPreferredSize();
235 return frame_->non_client_view()
236 ->GetWindowBoundsForClientBounds(gfx::Rect(pref))
237 .size();
238 }
239
240 const char* NonClientFrameViewMash::GetClassName() const {
241 return kViewClassName;
242 }
243
244 gfx::Size NonClientFrameViewMash::GetMinimumSize() const {
245 gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize());
246 return gfx::Size(
247 std::max(header_view_->GetMinimumWidth(), min_client_view_size.width()),
248 NonClientTopBorderHeight() + min_client_view_size.height());
249 }
250
251 gfx::Size NonClientFrameViewMash::GetMaximumSize() const {
252 gfx::Size max_client_size(frame_->client_view()->GetMaximumSize());
253 int width = 0;
254 int height = 0;
255
256 if (max_client_size.width() > 0)
257 width = std::max(header_view_->GetMinimumWidth(), max_client_size.width());
258 if (max_client_size.height() > 0)
259 height = NonClientTopBorderHeight() + max_client_size.height();
260
261 return gfx::Size(width, height);
262 }
263
264 void NonClientFrameViewMash::OnPaint(gfx::Canvas* canvas) {
265 canvas->Save();
266 NonClientFrameView::OnPaint(canvas);
267 canvas->Restore();
268
269 // The client app draws the client area. Make ours totally transparent so
270 // we only see the client apps client area.
271 canvas->FillRect(GetBoundsForClientView(), SK_ColorBLACK,
272 SkXfermode::kSrc_Mode);
273 }
274
275 void NonClientFrameViewMash::PaintChildren(const ui::PaintContext& context) {
276 NonClientFrameView::PaintChildren(context);
277
278 // The client app draws the client area. Make ours totally transparent so
279 // we only see the client apps client area.
280 ui::PaintRecorder recorder(context, size(), &paint_cache_);
281 recorder.canvas()->FillRect(GetBoundsForClientView(), SK_ColorBLACK,
282 SkXfermode::kSrc_Mode);
283 }
284
285 bool NonClientFrameViewMash::OnMousePressed(const ui::MouseEvent& event) {
286 return StartMoveLoopIfNecessary(event);
287 }
288
289 bool NonClientFrameViewMash::OnMouseDragged(const ui::MouseEvent& event) {
290 ContinueMove(event);
291 return move_loop_.get() != nullptr;
292 }
293
294 void NonClientFrameViewMash::OnMouseReleased(const ui::MouseEvent& event) {
295 ContinueMove(event);
296 }
297
298 void NonClientFrameViewMash::OnMouseCaptureLost() {
299 StopMove();
300 }
301
302 void NonClientFrameViewMash::OnWindowClientAreaChanged(
303 mus::Window* window,
304 const gfx::Insets& old_client_area) {
305 Layout();
306 // NonClientView (our parent) positions the client view based on bounds from
307 // us. We need to layout from parent to trigger a layout of the client view.
308 if (parent())
309 parent()->Layout();
310 SchedulePaint();
311 }
312
313 void NonClientFrameViewMash::OnWindowDestroyed(mus::Window* window) {
314 window_->RemoveObserver(this);
315 window_ = nullptr;
316 }
317
318 bool NonClientFrameViewMash::StartMoveLoopIfNecessary(const ui::Event& event) {
319 if (move_loop_)
320 return false;
321 // TODO(sky): convert MoveLoop to take ui::Event.
322 // TODO(sky): pass in hit test result.
323 move_loop_ = MoveLoop::Create(window_, *mus::mojom::Event::From(event));
324 return true;
325 }
326
327 void NonClientFrameViewMash::ContinueMove(const ui::Event& event) {
328 // TODO(sky): convert MoveLoop to take ui::Event.
329 if (move_loop_ &&
330 move_loop_->Move(*mus::mojom::Event::From(event)) == MoveLoop::DONE) {
331 move_loop_.reset();
332 }
333 }
334
335 void NonClientFrameViewMash::StopMove() {
336 move_loop_.reset();
337 }
338
339 views::View* NonClientFrameViewMash::GetHeaderView() {
340 return header_view_;
341 }
342
343 ////////////////////////////////////////////////////////////////////////////////
344 // NonClientFrameViewMash, private:
345
346 int NonClientFrameViewMash::NonClientTopBorderHeight() const {
347 return header_view_->GetPreferredHeight();
348 }
349
350 } // namespace wm
351 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/frame/non_client_frame_view_mash.h ('k') | mash/wm/move_loop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698