| OLD | NEW |
| 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 "ash/mus/frame/non_client_frame_view_mash.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/mus/frame/caption_buttons/frame_caption_button_container_view.h" |
| 12 #include "ash/mus/frame/default_header_painter.h" |
| 13 #include "ash/mus/frame/frame_border_hit_test_controller.h" |
| 14 #include "ash/mus/frame/header_painter.h" |
| 11 #include "base/macros.h" | 15 #include "base/macros.h" |
| 12 #include "components/mus/public/cpp/window.h" | 16 #include "components/mus/public/cpp/window.h" |
| 13 #include "components/mus/public/cpp/window_tree_client.h" | 17 #include "components/mus/public/cpp/window_tree_client.h" |
| 14 #include "grit/mash_wm_resources.h" | 18 #include "grit/ash_mus_resources.h" |
| 15 #include "mash/wm/frame/caption_buttons/frame_caption_button_container_view.h" | |
| 16 #include "mash/wm/frame/default_header_painter.h" | |
| 17 #include "mash/wm/frame/frame_border_hit_test_controller.h" | |
| 18 #include "mash/wm/frame/header_painter.h" | |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/compositor/paint_recorder.h" | 20 #include "ui/compositor/paint_recorder.h" |
| 21 #include "ui/events/mojo/input_events_type_converters.h" | 21 #include "ui/events/mojo/input_events_type_converters.h" |
| 22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
| 24 #include "ui/gfx/geometry/rect_conversions.h" | 24 #include "ui/gfx/geometry/rect_conversions.h" |
| 25 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 26 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| 27 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
| 28 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 29 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
| 30 | 30 |
| 31 namespace mash { | 31 namespace ash { |
| 32 namespace wm { | 32 namespace mus { |
| 33 | 33 |
| 34 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
| 35 // NonClientFrameViewMash::HeaderView | 35 // NonClientFrameViewMash::HeaderView |
| 36 | 36 |
| 37 // View which paints the header. | 37 // View which paints the header. |
| 38 class NonClientFrameViewMash::HeaderView : public views::View { | 38 class NonClientFrameViewMash::HeaderView : public views::View { |
| 39 public: | 39 public: |
| 40 // |frame| is the widget that the caption buttons act on. | 40 // |frame| is the widget that the caption buttons act on. |
| 41 HeaderView(views::Widget* frame, mus::Window* window); | 41 HeaderView(views::Widget* frame, ::mus::Window* window); |
| 42 ~HeaderView() override; | 42 ~HeaderView() override; |
| 43 | 43 |
| 44 // Schedules a repaint for the entire title. | 44 // Schedules a repaint for the entire title. |
| 45 void SchedulePaintForTitle(); | 45 void SchedulePaintForTitle(); |
| 46 | 46 |
| 47 // Tells the window controls to reset themselves to the normal state. | 47 // Tells the window controls to reset themselves to the normal state. |
| 48 void ResetWindowControls(); | 48 void ResetWindowControls(); |
| 49 | 49 |
| 50 // Returns the view's preferred height. | 50 // Returns the view's preferred height. |
| 51 int GetPreferredHeight() const; | 51 int GetPreferredHeight() const; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 69 private: | 69 private: |
| 70 // The widget that the caption buttons act on. | 70 // The widget that the caption buttons act on. |
| 71 views::Widget* frame_; | 71 views::Widget* frame_; |
| 72 | 72 |
| 73 // Helper for painting the header. | 73 // Helper for painting the header. |
| 74 std::unique_ptr<DefaultHeaderPainter> header_painter_; | 74 std::unique_ptr<DefaultHeaderPainter> header_painter_; |
| 75 | 75 |
| 76 // View which contains the window caption buttons. | 76 // View which contains the window caption buttons. |
| 77 FrameCaptionButtonContainerView* caption_button_container_; | 77 FrameCaptionButtonContainerView* caption_button_container_; |
| 78 | 78 |
| 79 mus::Window* window_; | 79 ::mus::Window* window_; |
| 80 | 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(HeaderView); | 81 DISALLOW_COPY_AND_ASSIGN(HeaderView); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 NonClientFrameViewMash::HeaderView::HeaderView(views::Widget* frame, | 84 NonClientFrameViewMash::HeaderView::HeaderView(views::Widget* frame, |
| 85 mus::Window* window) | 85 ::mus::Window* window) |
| 86 : frame_(frame), | 86 : frame_(frame), |
| 87 header_painter_(new DefaultHeaderPainter), | 87 header_painter_(new DefaultHeaderPainter), |
| 88 caption_button_container_(nullptr), | 88 caption_button_container_(nullptr), |
| 89 window_(window) { | 89 window_(window) { |
| 90 caption_button_container_ = new FrameCaptionButtonContainerView(frame_); | 90 caption_button_container_ = new FrameCaptionButtonContainerView(frame_); |
| 91 caption_button_container_->UpdateSizeButtonVisibility(); | 91 caption_button_container_->UpdateSizeButtonVisibility(); |
| 92 AddChildView(caption_button_container_); | 92 AddChildView(caption_button_container_); |
| 93 | 93 |
| 94 header_painter_->Init(frame_, this, caption_button_container_); | 94 header_painter_->Init(frame_, this, caption_button_container_); |
| 95 } | 95 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 /////////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////////// |
| 128 // NonClientFrameViewMash::HeaderView, views::View overrides: | 128 // NonClientFrameViewMash::HeaderView, views::View overrides: |
| 129 | 129 |
| 130 void NonClientFrameViewMash::HeaderView::Layout() { | 130 void NonClientFrameViewMash::HeaderView::Layout() { |
| 131 header_painter_->LayoutHeader(); | 131 header_painter_->LayoutHeader(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void NonClientFrameViewMash::HeaderView::OnPaint(gfx::Canvas* canvas) { | 134 void NonClientFrameViewMash::HeaderView::OnPaint(gfx::Canvas* canvas) { |
| 135 const mus::Window* focused_window = | 135 const ::mus::Window* focused_window = |
| 136 window_->window_tree()->GetFocusedWindow(); | 136 window_->window_tree()->GetFocusedWindow(); |
| 137 const bool paint_as_active = | 137 const bool paint_as_active = |
| 138 focused_window && window_->Contains(focused_window); | 138 focused_window && window_->Contains(focused_window); |
| 139 caption_button_container_->SetPaintAsActive(paint_as_active); | 139 caption_button_container_->SetPaintAsActive(paint_as_active); |
| 140 | 140 |
| 141 HeaderPainter::Mode header_mode = paint_as_active | 141 HeaderPainter::Mode header_mode = paint_as_active |
| 142 ? HeaderPainter::MODE_ACTIVE | 142 ? HeaderPainter::MODE_ACTIVE |
| 143 : HeaderPainter::MODE_INACTIVE; | 143 : HeaderPainter::MODE_INACTIVE; |
| 144 header_painter_->PaintHeader(canvas, header_mode); | 144 header_painter_->PaintHeader(canvas, header_mode); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void NonClientFrameViewMash::HeaderView::ChildPreferredSizeChanged( | 147 void NonClientFrameViewMash::HeaderView::ChildPreferredSizeChanged( |
| 148 views::View* child) { | 148 views::View* child) { |
| 149 // FrameCaptionButtonContainerView animates the visibility changes in | 149 // FrameCaptionButtonContainerView animates the visibility changes in |
| 150 // UpdateSizeButtonVisibility(false). Due to this a new size is not available | 150 // UpdateSizeButtonVisibility(false). Due to this a new size is not available |
| 151 // until the completion of the animation. Layout in response to the preferred | 151 // until the completion of the animation. Layout in response to the preferred |
| 152 // size changes. | 152 // size changes. |
| 153 if (child != caption_button_container_) | 153 if (child != caption_button_container_) |
| 154 return; | 154 return; |
| 155 parent()->Layout(); | 155 parent()->Layout(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
| 159 // NonClientFrameViewMash, public: | 159 // NonClientFrameViewMash, public: |
| 160 | 160 |
| 161 // static | 161 // static |
| 162 const char NonClientFrameViewMash::kViewClassName[] = "NonClientFrameViewMash"; | 162 const char NonClientFrameViewMash::kViewClassName[] = "NonClientFrameViewMash"; |
| 163 | 163 |
| 164 NonClientFrameViewMash::NonClientFrameViewMash(views::Widget* frame, | 164 NonClientFrameViewMash::NonClientFrameViewMash(views::Widget* frame, |
| 165 mus::Window* window) | 165 ::mus::Window* window) |
| 166 : frame_(frame), | 166 : frame_(frame), |
| 167 window_(window), | 167 window_(window), |
| 168 header_view_(new HeaderView(frame, window)) { | 168 header_view_(new HeaderView(frame, window)) { |
| 169 // |header_view_| is set as the non client view's overlay view so that it can | 169 // |header_view_| is set as the non client view's overlay view so that it can |
| 170 // overlay the web contents in immersive fullscreen. | 170 // overlay the web contents in immersive fullscreen. |
| 171 AddChildView(header_view_); | 171 AddChildView(header_view_); |
| 172 window_->AddObserver(this); | 172 window_->AddObserver(this); |
| 173 window_->window_tree()->AddObserver(this); | 173 window_->window_tree()->AddObserver(this); |
| 174 } | 174 } |
| 175 | 175 |
| 176 NonClientFrameViewMash::~NonClientFrameViewMash() { | 176 NonClientFrameViewMash::~NonClientFrameViewMash() { |
| 177 RemoveObservers(); | 177 RemoveObservers(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 // static | 180 // static |
| 181 gfx::Insets NonClientFrameViewMash::GetPreferredClientAreaInsets() { | 181 gfx::Insets NonClientFrameViewMash::GetPreferredClientAreaInsets() { |
| 182 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 182 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 183 const int header_height = | 183 const int header_height = |
| 184 rb.GetImageSkiaNamed(IDR_MASH_WM_WINDOW_CONTROL_BACKGROUND_P) | 184 rb.GetImageSkiaNamed(IDR_ASH_MUS_WINDOW_CONTROL_BACKGROUND_P) |
| 185 ->size() | 185 ->size() |
| 186 .height(); | 186 .height(); |
| 187 return gfx::Insets(header_height, 0, 0, 0); | 187 return gfx::Insets(header_height, 0, 0, 0); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // static | 190 // static |
| 191 int NonClientFrameViewMash::GetMaxTitleBarButtonWidth() { | 191 int NonClientFrameViewMash::GetMaxTitleBarButtonWidth() { |
| 192 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 192 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 193 return rb.GetImageSkiaNamed(IDR_MASH_WM_WINDOW_CONTROL_BACKGROUND_P) | 193 return rb.GetImageSkiaNamed(IDR_ASH_MUS_WINDOW_CONTROL_BACKGROUND_P) |
| 194 ->size() | 194 ->size() |
| 195 .width() * | 195 .width() * |
| 196 3; | 196 3; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void NonClientFrameViewMash::SetFrameColors(SkColor active_frame_color, | 199 void NonClientFrameViewMash::SetFrameColors(SkColor active_frame_color, |
| 200 SkColor inactive_frame_color) { | 200 SkColor inactive_frame_color) { |
| 201 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); | 201 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); |
| 202 } | 202 } |
| 203 | 203 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 NonClientFrameView::PaintChildren(context); | 301 NonClientFrameView::PaintChildren(context); |
| 302 | 302 |
| 303 // The client app draws the client area. Make ours totally transparent so | 303 // The client app draws the client area. Make ours totally transparent so |
| 304 // we only see the client apps client area. | 304 // we only see the client apps client area. |
| 305 ui::PaintRecorder recorder(context, size(), &paint_cache_); | 305 ui::PaintRecorder recorder(context, size(), &paint_cache_); |
| 306 recorder.canvas()->FillRect(GetBoundsForClientView(), SK_ColorBLACK, | 306 recorder.canvas()->FillRect(GetBoundsForClientView(), SK_ColorBLACK, |
| 307 SkXfermode::kSrc_Mode); | 307 SkXfermode::kSrc_Mode); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void NonClientFrameViewMash::OnWindowClientAreaChanged( | 310 void NonClientFrameViewMash::OnWindowClientAreaChanged( |
| 311 mus::Window* window, | 311 ::mus::Window* window, |
| 312 const gfx::Insets& old_client_area, | 312 const gfx::Insets& old_client_area, |
| 313 const std::vector<gfx::Rect>& old_additional_client_area) { | 313 const std::vector<gfx::Rect>& old_additional_client_area) { |
| 314 // Only the insets effect the rendering. | 314 // Only the insets effect the rendering. |
| 315 if (old_client_area == window->client_area()) | 315 if (old_client_area == window->client_area()) |
| 316 return; | 316 return; |
| 317 | 317 |
| 318 Layout(); | 318 Layout(); |
| 319 // NonClientView (our parent) positions the client view based on bounds from | 319 // NonClientView (our parent) positions the client view based on bounds from |
| 320 // us. We need to layout from parent to trigger a layout of the client view. | 320 // us. We need to layout from parent to trigger a layout of the client view. |
| 321 if (parent()) | 321 if (parent()) |
| 322 parent()->Layout(); | 322 parent()->Layout(); |
| 323 SchedulePaint(); | 323 SchedulePaint(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void NonClientFrameViewMash::OnWindowDestroyed(mus::Window* window) { | 326 void NonClientFrameViewMash::OnWindowDestroyed(::mus::Window* window) { |
| 327 RemoveObservers(); | 327 RemoveObservers(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void NonClientFrameViewMash::OnWindowSharedPropertyChanged( | 330 void NonClientFrameViewMash::OnWindowSharedPropertyChanged( |
| 331 mus::Window* window, | 331 ::mus::Window* window, |
| 332 const std::string& name, | 332 const std::string& name, |
| 333 const std::vector<uint8_t>* old_data, | 333 const std::vector<uint8_t>* old_data, |
| 334 const std::vector<uint8_t>* new_data) { | 334 const std::vector<uint8_t>* new_data) { |
| 335 if (name == mus::mojom::WindowManager::kResizeBehavior_Property) | 335 if (name == ::mus::mojom::WindowManager::kResizeBehavior_Property) |
| 336 header_view_->SizeConstraintsChanged(); | 336 header_view_->SizeConstraintsChanged(); |
| 337 else if (name == mus::mojom::WindowManager::kWindowTitle_Property) | 337 else if (name == ::mus::mojom::WindowManager::kWindowTitle_Property) |
| 338 header_view_->SchedulePaintForTitle(); | 338 header_view_->SchedulePaintForTitle(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 views::View* NonClientFrameViewMash::GetHeaderView() { | 341 views::View* NonClientFrameViewMash::GetHeaderView() { |
| 342 return header_view_; | 342 return header_view_; |
| 343 } | 343 } |
| 344 | 344 |
| 345 //////////////////////////////////////////////////////////////////////////////// | 345 //////////////////////////////////////////////////////////////////////////////// |
| 346 // NonClientFrameViewMash, private: | 346 // NonClientFrameViewMash, private: |
| 347 | 347 |
| 348 int NonClientFrameViewMash::NonClientTopBorderHeight() const { | 348 int NonClientFrameViewMash::NonClientTopBorderHeight() const { |
| 349 return header_view_->GetPreferredHeight(); | 349 return header_view_->GetPreferredHeight(); |
| 350 } | 350 } |
| 351 | 351 |
| 352 void NonClientFrameViewMash::RemoveObservers() { | 352 void NonClientFrameViewMash::RemoveObservers() { |
| 353 if (!window_) | 353 if (!window_) |
| 354 return; | 354 return; |
| 355 | 355 |
| 356 window_->RemoveObserver(this); | 356 window_->RemoveObserver(this); |
| 357 window_->window_tree()->RemoveObserver(this); | 357 window_->window_tree()->RemoveObserver(this); |
| 358 window_ = nullptr; | 358 window_ = nullptr; |
| 359 } | 359 } |
| 360 | 360 |
| 361 void NonClientFrameViewMash::OnWindowTreeFocusChanged(mus::Window* gained_focus, | 361 void NonClientFrameViewMash::OnWindowTreeFocusChanged( |
| 362 mus::Window* lost_focus) { | 362 ::mus::Window* gained_focus, |
| 363 ::mus::Window* lost_focus) { |
| 363 const bool had_focus = lost_focus && window_->Contains(lost_focus); | 364 const bool had_focus = lost_focus && window_->Contains(lost_focus); |
| 364 const bool has_focus = gained_focus && window_->Contains(gained_focus); | 365 const bool has_focus = gained_focus && window_->Contains(gained_focus); |
| 365 if (had_focus != has_focus) | 366 if (had_focus != has_focus) |
| 366 SchedulePaint(); | 367 SchedulePaint(); |
| 367 } | 368 } |
| 368 | 369 |
| 369 } // namespace wm | 370 } // namespace mus |
| 370 } // namespace mash | 371 } // namespace ash |
| OLD | NEW |