| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/frame/header_view.h" | 5 #include "ash/frame/header_view.h" |
| 6 | 6 |
| 7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 8 #include "ash/frame/default_header_painter.h" | 8 #include "ash/frame/default_header_painter.h" |
| 9 #include "ash/session/session_state_delegate.h" | |
| 10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 11 #include "ash/shell_port.h" | |
| 12 #include "ash/wm_window.h" | 10 #include "ash/wm_window.h" |
| 13 #include "ui/gfx/canvas.h" | |
| 14 #include "ui/views/controls/image_view.h" | 11 #include "ui/views/controls/image_view.h" |
| 15 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
| 16 | 13 |
| 17 namespace ash { | 14 namespace ash { |
| 18 | 15 |
| 19 HeaderView::HeaderView(views::Widget* target_widget, | 16 HeaderView::HeaderView(views::Widget* target_widget, |
| 20 mojom::WindowStyle window_style) | 17 mojom::WindowStyle window_style) |
| 21 : target_widget_(target_widget), | 18 : target_widget_(target_widget), |
| 22 header_painter_(base::MakeUnique<DefaultHeaderPainter>(window_style)), | 19 header_painter_(base::MakeUnique<DefaultHeaderPainter>(window_style)), |
| 23 avatar_icon_(nullptr), | 20 avatar_icon_(nullptr), |
| 24 caption_button_container_(nullptr), | 21 caption_button_container_(nullptr), |
| 25 fullscreen_visible_fraction_(0) { | 22 fullscreen_visible_fraction_(0) { |
| 26 caption_button_container_ = | 23 caption_button_container_ = |
| 27 new FrameCaptionButtonContainerView(target_widget_); | 24 new FrameCaptionButtonContainerView(target_widget_); |
| 28 caption_button_container_->UpdateSizeButtonVisibility(); | 25 caption_button_container_->UpdateSizeButtonVisibility(); |
| 29 AddChildView(caption_button_container_); | 26 AddChildView(caption_button_container_); |
| 30 | 27 |
| 31 header_painter_->Init(target_widget_, this, caption_button_container_); | 28 header_painter_->Init(target_widget_, this, caption_button_container_); |
| 32 UpdateAvatarIcon(); | |
| 33 | 29 |
| 34 Shell::Get()->AddShellObserver(this); | 30 Shell::Get()->AddShellObserver(this); |
| 35 } | 31 } |
| 36 | 32 |
| 37 HeaderView::~HeaderView() { | 33 HeaderView::~HeaderView() { |
| 38 Shell::Get()->RemoveShellObserver(this); | 34 Shell::Get()->RemoveShellObserver(this); |
| 39 } | 35 } |
| 40 | 36 |
| 41 void HeaderView::SchedulePaintForTitle() { | 37 void HeaderView::SchedulePaintForTitle() { |
| 42 header_painter_->SchedulePaintForTitle(); | 38 header_painter_->SchedulePaintForTitle(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 58 // Calculating the preferred height requires at least one Layout(). | 54 // Calculating the preferred height requires at least one Layout(). |
| 59 if (!did_layout_) | 55 if (!did_layout_) |
| 60 Layout(); | 56 Layout(); |
| 61 return header_painter_->GetHeaderHeightForPainting(); | 57 return header_painter_->GetHeaderHeightForPainting(); |
| 62 } | 58 } |
| 63 | 59 |
| 64 int HeaderView::GetMinimumWidth() const { | 60 int HeaderView::GetMinimumWidth() const { |
| 65 return header_painter_->GetMinimumHeaderWidth(); | 61 return header_painter_->GetMinimumHeaderWidth(); |
| 66 } | 62 } |
| 67 | 63 |
| 68 void HeaderView::UpdateAvatarIcon() { | 64 void HeaderView::SetAvatarIcon(const gfx::ImageSkia& avatar) { |
| 69 SessionStateDelegate* delegate = ShellPort::Get()->GetSessionStateDelegate(); | 65 const bool show = !avatar.isNull(); |
| 70 WmWindow* window = WmWindow::Get(target_widget_->GetNativeWindow()); | |
| 71 bool show = delegate->ShouldShowAvatar(window); | |
| 72 if (!show) { | 66 if (!show) { |
| 73 if (!avatar_icon_) | 67 if (!avatar_icon_) |
| 74 return; | 68 return; |
| 75 delete avatar_icon_; | 69 delete avatar_icon_; |
| 76 avatar_icon_ = nullptr; | 70 avatar_icon_ = nullptr; |
| 77 } else { | 71 } else { |
| 78 gfx::ImageSkia image = delegate->GetAvatarImageForWindow(window); | 72 DCHECK_EQ(avatar.width(), avatar.height()); |
| 79 DCHECK_EQ(image.width(), image.height()); | |
| 80 if (!avatar_icon_) { | 73 if (!avatar_icon_) { |
| 81 avatar_icon_ = new views::ImageView(); | 74 avatar_icon_ = new views::ImageView(); |
| 82 AddChildView(avatar_icon_); | 75 AddChildView(avatar_icon_); |
| 83 } | 76 } |
| 84 avatar_icon_->SetImage(image); | 77 avatar_icon_->SetImage(avatar); |
| 85 } | 78 } |
| 86 header_painter_->UpdateLeftHeaderView(avatar_icon_); | 79 header_painter_->UpdateLeftHeaderView(avatar_icon_); |
| 87 Layout(); | 80 Layout(); |
| 88 } | 81 } |
| 89 | 82 |
| 90 void HeaderView::SizeConstraintsChanged() { | 83 void HeaderView::SizeConstraintsChanged() { |
| 91 caption_button_container_->ResetWindowControls(); | 84 caption_button_container_->ResetWindowControls(); |
| 92 caption_button_container_->UpdateSizeButtonVisibility(); | 85 caption_button_container_->UpdateSizeButtonVisibility(); |
| 93 Layout(); | 86 Layout(); |
| 94 } | 87 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 gfx::Rect visible_bounds(GetVisibleBounds()); | 187 gfx::Rect visible_bounds(GetVisibleBounds()); |
| 195 gfx::Point visible_origin_in_screen(visible_bounds.origin()); | 188 gfx::Point visible_origin_in_screen(visible_bounds.origin()); |
| 196 views::View::ConvertPointToScreen(this, &visible_origin_in_screen); | 189 views::View::ConvertPointToScreen(this, &visible_origin_in_screen); |
| 197 std::vector<gfx::Rect> bounds_in_screen; | 190 std::vector<gfx::Rect> bounds_in_screen; |
| 198 bounds_in_screen.push_back( | 191 bounds_in_screen.push_back( |
| 199 gfx::Rect(visible_origin_in_screen, visible_bounds.size())); | 192 gfx::Rect(visible_origin_in_screen, visible_bounds.size())); |
| 200 return bounds_in_screen; | 193 return bounds_in_screen; |
| 201 } | 194 } |
| 202 | 195 |
| 203 } // namespace ash | 196 } // namespace ash |
| OLD | NEW |