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

Unified Diff: ash/common/frame/header_view.cc

Issue 2248383003: Moves HeaderView into it's own .h/.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/frame/header_view.cc
diff --git a/ash/common/frame/header_view.cc b/ash/common/frame/header_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ee44d663f05fdd3bf6fc3c4f8bdf95a96ffc83c9
--- /dev/null
+++ b/ash/common/frame/header_view.cc
@@ -0,0 +1,193 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/common/frame/header_view.h"
+
+#include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h"
+#include "ash/common/frame/default_header_painter.h"
+#include "ash/common/material_design/material_design_controller.h"
+#include "ash/common/session/session_state_delegate.h"
+#include "ash/common/wm_lookup.h"
+#include "ash/common/wm_shell.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+
+HeaderView::HeaderView(views::Widget* target_widget)
+ : target_widget_(target_widget),
+ header_painter_(new DefaultHeaderPainter),
+ avatar_icon_(nullptr),
+ caption_button_container_(nullptr),
+ fullscreen_visible_fraction_(0) {
+ caption_button_container_ =
+ new FrameCaptionButtonContainerView(target_widget_);
+ caption_button_container_->UpdateSizeButtonVisibility();
+ AddChildView(caption_button_container_);
+
+ header_painter_->Init(target_widget_, this, caption_button_container_);
+ UpdateAvatarIcon();
+
+ WmShell::Get()->AddShellObserver(this);
+}
+
+HeaderView::~HeaderView() {
+ WmShell::Get()->RemoveShellObserver(this);
+}
+
+void HeaderView::SchedulePaintForTitle() {
+ header_painter_->SchedulePaintForTitle();
+}
+
+void HeaderView::ResetWindowControls() {
+ caption_button_container_->ResetWindowControls();
+}
+
+int HeaderView::GetPreferredOnScreenHeight() const {
+ if (target_widget_->IsFullscreen()) {
+ return static_cast<int>(GetPreferredHeight() *
+ fullscreen_visible_fraction_);
+ }
+ return GetPreferredHeight();
+}
+
+int HeaderView::GetPreferredHeight() const {
+ return header_painter_->GetHeaderHeightForPainting();
+}
+
+int HeaderView::GetMinimumWidth() const {
+ return header_painter_->GetMinimumHeaderWidth();
+}
+
+void HeaderView::UpdateAvatarIcon() {
+ SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
+ WmWindow* window = WmLookup::Get()->GetWindowForWidget(target_widget_);
+ bool show = delegate->ShouldShowAvatar(window);
+ if (!show) {
+ if (!avatar_icon_)
+ return;
+ delete avatar_icon_;
+ avatar_icon_ = nullptr;
+ } else {
+ gfx::ImageSkia image = delegate->GetAvatarImageForWindow(window);
+ DCHECK_EQ(image.width(), image.height());
+ if (!avatar_icon_) {
+ avatar_icon_ = new views::ImageView();
+ AddChildView(avatar_icon_);
+ }
+ avatar_icon_->SetImage(image);
+ }
+ header_painter_->UpdateLeftHeaderView(avatar_icon_);
+ Layout();
+}
+
+void HeaderView::SizeConstraintsChanged() {
+ caption_button_container_->ResetWindowControls();
+ caption_button_container_->UpdateSizeButtonVisibility();
+ Layout();
+}
+
+void HeaderView::SetFrameColors(SkColor active_frame_color,
+ SkColor inactive_frame_color) {
+ header_painter_->SetFrameColors(active_frame_color, inactive_frame_color);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// HeaderView, views::View overrides:
+
+void HeaderView::Layout() {
+ header_painter_->LayoutHeader();
+}
+
+void HeaderView::OnPaint(gfx::Canvas* canvas) {
+ bool paint_as_active =
+ target_widget_->non_client_view()->frame_view()->ShouldPaintAsActive();
+ caption_button_container_->SetPaintAsActive(paint_as_active);
+
+ HeaderPainter::Mode header_mode = paint_as_active
+ ? HeaderPainter::MODE_ACTIVE
+ : HeaderPainter::MODE_INACTIVE;
+ header_painter_->PaintHeader(canvas, header_mode);
+}
+
+void HeaderView::ChildPreferredSizeChanged(views::View* child) {
+ // FrameCaptionButtonContainerView animates the visibility changes in
+ // UpdateSizeButtonVisibility(false). Due to this a new size is not available
+ // until the completion of the animation. Layout in response to the preferred
+ // size changes.
+ if (child != caption_button_container_)
+ return;
+ parent()->Layout();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// HeaderView, ShellObserver overrides:
+
+void HeaderView::OnOverviewModeStarting() {
+ if (MaterialDesignController::IsOverviewMaterial())
+ caption_button_container_->SetVisible(false);
+}
+
+void HeaderView::OnOverviewModeEnded() {
+ if (MaterialDesignController::IsOverviewMaterial())
+ caption_button_container_->SetVisible(true);
+}
+
+void HeaderView::OnMaximizeModeStarted() {
+ caption_button_container_->UpdateSizeButtonVisibility();
+ parent()->Layout();
+}
+
+void HeaderView::OnMaximizeModeEnded() {
+ caption_button_container_->UpdateSizeButtonVisibility();
+ parent()->Layout();
+}
+
+views::View* HeaderView::avatar_icon() const {
+ return avatar_icon_;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// HeaderView,
+// WmImmersiveFullscreenControllerDelegate overrides:
+
+void HeaderView::OnImmersiveRevealStarted() {
+ fullscreen_visible_fraction_ = 0;
+ SetPaintToLayer(true);
+ layer()->SetFillsBoundsOpaquely(false);
+ parent()->Layout();
+}
+
+void HeaderView::OnImmersiveRevealEnded() {
+ fullscreen_visible_fraction_ = 0;
+ SetPaintToLayer(false);
+ parent()->Layout();
+}
+
+void HeaderView::OnImmersiveFullscreenExited() {
+ fullscreen_visible_fraction_ = 0;
+ SetPaintToLayer(false);
+ parent()->Layout();
+}
+
+void HeaderView::SetVisibleFraction(double visible_fraction) {
+ if (fullscreen_visible_fraction_ != visible_fraction) {
+ fullscreen_visible_fraction_ = visible_fraction;
+ parent()->Layout();
+ }
+}
+
+std::vector<gfx::Rect> HeaderView::GetVisibleBoundsInScreen() const {
+ // TODO(pkotwicz): Implement views::View::ConvertRectToScreen().
+ gfx::Rect visible_bounds(GetVisibleBounds());
+ gfx::Point visible_origin_in_screen(visible_bounds.origin());
+ views::View::ConvertPointToScreen(this, &visible_origin_in_screen);
+ std::vector<gfx::Rect> bounds_in_screen;
+ bounds_in_screen.push_back(
+ gfx::Rect(visible_origin_in_screen, visible_bounds.size()));
+ return bounds_in_screen;
+}
+
+} // namespace ash
« no previous file with comments | « ash/common/frame/header_view.h ('k') | ash/common/wm/immersive/wm_immersive_fullscreen_controller_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698