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

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

Issue 1848653006: Random wm frame painting fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: override Created 4 years, 8 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 | « mash/wm/frame/non_client_frame_view_mash.h ('k') | mash/wm/non_client_frame_controller.h » ('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 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 "mash/wm/frame/non_client_frame_view_mash.h" 5 #include "mash/wm/frame/non_client_frame_view_mash.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "components/mus/public/cpp/window.h" 11 #include "components/mus/public/cpp/window.h"
12 #include "components/mus/public/cpp/window_tree_connection.h"
12 #include "grit/mash_wm_resources.h" 13 #include "grit/mash_wm_resources.h"
13 #include "mash/wm/frame/caption_buttons/frame_caption_button_container_view.h" 14 #include "mash/wm/frame/caption_buttons/frame_caption_button_container_view.h"
14 #include "mash/wm/frame/default_header_painter.h" 15 #include "mash/wm/frame/default_header_painter.h"
15 #include "mash/wm/frame/frame_border_hit_test_controller.h" 16 #include "mash/wm/frame/frame_border_hit_test_controller.h"
16 #include "mash/wm/frame/header_painter.h" 17 #include "mash/wm/frame/header_painter.h"
17 #include "mojo/converters/input_events/input_events_type_converters.h" 18 #include "mojo/converters/input_events/input_events_type_converters.h"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/compositor/paint_recorder.h" 20 #include "ui/compositor/paint_recorder.h"
20 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/geometry/rect_conversions.h" 23 #include "ui/gfx/geometry/rect_conversions.h"
23 #include "ui/gfx/geometry/size.h" 24 #include "ui/gfx/geometry/size.h"
24 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
25 #include "ui/views/view.h" 26 #include "ui/views/view.h"
26 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
27 #include "ui/views/widget/widget_delegate.h" 28 #include "ui/views/widget/widget_delegate.h"
28 29
29 namespace mash { 30 namespace mash {
30 namespace wm { 31 namespace wm {
31 32
32 /////////////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////////////
33 // NonClientFrameViewMash::HeaderView 34 // NonClientFrameViewMash::HeaderView
34 35
35 // View which paints the header. 36 // View which paints the header.
36 class NonClientFrameViewMash::HeaderView : public views::View { 37 class NonClientFrameViewMash::HeaderView : public views::View {
37 public: 38 public:
38 // |frame| is the widget that the caption buttons act on. 39 // |frame| is the widget that the caption buttons act on.
39 explicit HeaderView(views::Widget* frame); 40 HeaderView(views::Widget* frame, mus::Window* window);
40 ~HeaderView() override; 41 ~HeaderView() override;
41 42
42 // Schedules a repaint for the entire title. 43 // Schedules a repaint for the entire title.
43 void SchedulePaintForTitle(); 44 void SchedulePaintForTitle();
44 45
45 // Tells the window controls to reset themselves to the normal state. 46 // Tells the window controls to reset themselves to the normal state.
46 void ResetWindowControls(); 47 void ResetWindowControls();
47 48
48 // Returns the view's preferred height. 49 // Returns the view's preferred height.
49 int GetPreferredHeight() const; 50 int GetPreferredHeight() const;
(...skipping 17 matching lines...) Expand all
67 private: 68 private:
68 // The widget that the caption buttons act on. 69 // The widget that the caption buttons act on.
69 views::Widget* frame_; 70 views::Widget* frame_;
70 71
71 // Helper for painting the header. 72 // Helper for painting the header.
72 scoped_ptr<DefaultHeaderPainter> header_painter_; 73 scoped_ptr<DefaultHeaderPainter> header_painter_;
73 74
74 // View which contains the window caption buttons. 75 // View which contains the window caption buttons.
75 FrameCaptionButtonContainerView* caption_button_container_; 76 FrameCaptionButtonContainerView* caption_button_container_;
76 77
78 mus::Window* window_;
79
77 DISALLOW_COPY_AND_ASSIGN(HeaderView); 80 DISALLOW_COPY_AND_ASSIGN(HeaderView);
78 }; 81 };
79 82
80 NonClientFrameViewMash::HeaderView::HeaderView(views::Widget* frame) 83 NonClientFrameViewMash::HeaderView::HeaderView(views::Widget* frame,
84 mus::Window* window)
81 : frame_(frame), 85 : frame_(frame),
82 header_painter_(new DefaultHeaderPainter), 86 header_painter_(new DefaultHeaderPainter),
83 caption_button_container_(nullptr) { 87 caption_button_container_(nullptr),
88 window_(window) {
84 caption_button_container_ = new FrameCaptionButtonContainerView(frame_); 89 caption_button_container_ = new FrameCaptionButtonContainerView(frame_);
85 caption_button_container_->UpdateSizeButtonVisibility(); 90 caption_button_container_->UpdateSizeButtonVisibility();
86 AddChildView(caption_button_container_); 91 AddChildView(caption_button_container_);
87 92
88 header_painter_->Init(frame_, this, caption_button_container_); 93 header_painter_->Init(frame_, this, caption_button_container_);
89 } 94 }
90 95
91 NonClientFrameViewMash::HeaderView::~HeaderView() {} 96 NonClientFrameViewMash::HeaderView::~HeaderView() {}
92 97
93 void NonClientFrameViewMash::HeaderView::SchedulePaintForTitle() { 98 void NonClientFrameViewMash::HeaderView::SchedulePaintForTitle() {
(...skipping 25 matching lines...) Expand all
119 } 124 }
120 125
121 /////////////////////////////////////////////////////////////////////////////// 126 ///////////////////////////////////////////////////////////////////////////////
122 // NonClientFrameViewMash::HeaderView, views::View overrides: 127 // NonClientFrameViewMash::HeaderView, views::View overrides:
123 128
124 void NonClientFrameViewMash::HeaderView::Layout() { 129 void NonClientFrameViewMash::HeaderView::Layout() {
125 header_painter_->LayoutHeader(); 130 header_painter_->LayoutHeader();
126 } 131 }
127 132
128 void NonClientFrameViewMash::HeaderView::OnPaint(gfx::Canvas* canvas) { 133 void NonClientFrameViewMash::HeaderView::OnPaint(gfx::Canvas* canvas) {
129 bool paint_as_active = 134 const mus::Window* focused_window = window_->connection()->GetFocusedWindow();
130 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); 135 const bool paint_as_active =
136 focused_window && window_->Contains(focused_window);
131 caption_button_container_->SetPaintAsActive(paint_as_active); 137 caption_button_container_->SetPaintAsActive(paint_as_active);
132 138
133 HeaderPainter::Mode header_mode = paint_as_active 139 HeaderPainter::Mode header_mode = paint_as_active
134 ? HeaderPainter::MODE_ACTIVE 140 ? HeaderPainter::MODE_ACTIVE
135 : HeaderPainter::MODE_INACTIVE; 141 : HeaderPainter::MODE_INACTIVE;
136 header_painter_->PaintHeader(canvas, header_mode); 142 header_painter_->PaintHeader(canvas, header_mode);
137 } 143 }
138 144
139 void NonClientFrameViewMash::HeaderView::ChildPreferredSizeChanged( 145 void NonClientFrameViewMash::HeaderView::ChildPreferredSizeChanged(
140 views::View* child) { 146 views::View* child) {
141 // FrameCaptionButtonContainerView animates the visibility changes in 147 // FrameCaptionButtonContainerView animates the visibility changes in
142 // UpdateSizeButtonVisibility(false). Due to this a new size is not available 148 // UpdateSizeButtonVisibility(false). Due to this a new size is not available
143 // until the completion of the animation. Layout in response to the preferred 149 // until the completion of the animation. Layout in response to the preferred
144 // size changes. 150 // size changes.
145 if (child != caption_button_container_) 151 if (child != caption_button_container_)
146 return; 152 return;
147 parent()->Layout(); 153 parent()->Layout();
148 } 154 }
149 155
150 //////////////////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////////////////
151 // NonClientFrameViewMash, public: 157 // NonClientFrameViewMash, public:
152 158
153 // static 159 // static
154 const char NonClientFrameViewMash::kViewClassName[] = "NonClientFrameViewMash"; 160 const char NonClientFrameViewMash::kViewClassName[] = "NonClientFrameViewMash";
155 161
156 NonClientFrameViewMash::NonClientFrameViewMash(views::Widget* frame, 162 NonClientFrameViewMash::NonClientFrameViewMash(views::Widget* frame,
157 mus::Window* window) 163 mus::Window* window)
158 : frame_(frame), window_(window), header_view_(new HeaderView(frame)) { 164 : frame_(frame),
165 window_(window),
166 header_view_(new HeaderView(frame, window)) {
159 // |header_view_| is set as the non client view's overlay view so that it can 167 // |header_view_| is set as the non client view's overlay view so that it can
160 // overlay the web contents in immersive fullscreen. 168 // overlay the web contents in immersive fullscreen.
161 AddChildView(header_view_); 169 AddChildView(header_view_);
162 window_->AddObserver(this); 170 window_->AddObserver(this);
171 window_->connection()->AddObserver(this);
163 } 172 }
164 173
165 NonClientFrameViewMash::~NonClientFrameViewMash() { 174 NonClientFrameViewMash::~NonClientFrameViewMash() {
166 if (window_) 175 RemoveObservers();
167 window_->RemoveObserver(this);
168 } 176 }
169 177
170 // static 178 // static
171 gfx::Insets NonClientFrameViewMash::GetPreferredClientAreaInsets() { 179 gfx::Insets NonClientFrameViewMash::GetPreferredClientAreaInsets() {
172 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 180 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
173 const int header_height = 181 const int header_height =
174 rb.GetImageSkiaNamed(IDR_MASH_WM_WINDOW_CONTROL_BACKGROUND_P) 182 rb.GetImageSkiaNamed(IDR_MASH_WM_WINDOW_CONTROL_BACKGROUND_P)
175 ->size() 183 ->size()
176 .height(); 184 .height();
177 return gfx::Insets(header_height, 0, 0, 0); 185 return gfx::Insets(header_height, 0, 0, 0);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 309
302 Layout(); 310 Layout();
303 // NonClientView (our parent) positions the client view based on bounds from 311 // NonClientView (our parent) positions the client view based on bounds from
304 // us. We need to layout from parent to trigger a layout of the client view. 312 // us. We need to layout from parent to trigger a layout of the client view.
305 if (parent()) 313 if (parent())
306 parent()->Layout(); 314 parent()->Layout();
307 SchedulePaint(); 315 SchedulePaint();
308 } 316 }
309 317
310 void NonClientFrameViewMash::OnWindowDestroyed(mus::Window* window) { 318 void NonClientFrameViewMash::OnWindowDestroyed(mus::Window* window) {
311 window_->RemoveObserver(this); 319 RemoveObservers();
312 window_ = nullptr; 320 }
321
322 void NonClientFrameViewMash::OnWindowSharedPropertyChanged(
323 mus::Window* window,
324 const std::string& name,
325 const std::vector<uint8_t>* old_data,
326 const std::vector<uint8_t>* new_data) {
327 if (name == mus::mojom::WindowManager::kResizeBehavior_Property)
328 header_view_->SizeConstraintsChanged();
329 else if (name == mus::mojom::WindowManager::kWindowTitle_Property)
330 header_view_->SchedulePaintForTitle();
313 } 331 }
314 332
315 views::View* NonClientFrameViewMash::GetHeaderView() { 333 views::View* NonClientFrameViewMash::GetHeaderView() {
316 return header_view_; 334 return header_view_;
317 } 335 }
318 336
319 //////////////////////////////////////////////////////////////////////////////// 337 ////////////////////////////////////////////////////////////////////////////////
320 // NonClientFrameViewMash, private: 338 // NonClientFrameViewMash, private:
321 339
322 int NonClientFrameViewMash::NonClientTopBorderHeight() const { 340 int NonClientFrameViewMash::NonClientTopBorderHeight() const {
323 return header_view_->GetPreferredHeight(); 341 return header_view_->GetPreferredHeight();
324 } 342 }
325 343
344 void NonClientFrameViewMash::RemoveObservers() {
345 if (!window_)
346 return;
347
348 window_->RemoveObserver(this);
349 window_->connection()->RemoveObserver(this);
350 window_ = nullptr;
351 }
352
353 void NonClientFrameViewMash::OnWindowTreeFocusChanged(mus::Window* gained_focus,
354 mus::Window* lost_focus) {
355 const bool had_focus = lost_focus && window_->Contains(lost_focus);
356 const bool has_focus = gained_focus && window_->Contains(gained_focus);
357 if (had_focus != has_focus)
358 SchedulePaint();
359 }
360
326 } // namespace wm 361 } // namespace wm
327 } // namespace mash 362 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/frame/non_client_frame_view_mash.h ('k') | mash/wm/non_client_frame_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698