Commit c11a6807 authored by sky's avatar sky Committed by Commit bot

Moves HeaderView into it's own .h/.cc

This way I can use it outside of CustomFrameViewAsh.

BUG=548435
TEST=none
R=jamescook@chromium.org

Review-Url: https://codereview.chromium.org/2248383003
Cr-Commit-Position: refs/heads/master@{#412635}
parent 98433595
......@@ -92,6 +92,8 @@
'common/frame/header_painter.h',
'common/frame/header_painter_util.cc',
'common/frame/header_painter_util.h',
'common/frame/header_view.cc',
'common/frame/header_view.h',
'common/gpu_support.h',
'common/gpu_support_stub.cc',
'common/gpu_support_stub.h',
......
......@@ -9,12 +9,8 @@
#include "ash/common/ash_switches.h"
#include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/common/frame/default_header_painter.h"
#include "ash/common/frame/frame_border_hit_test.h"
#include "ash/common/frame/header_painter.h"
#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/shell_observer.h"
#include "ash/common/frame/header_view.h"
#include "ash/common/wm/immersive/wm_immersive_fullscreen_controller.h"
#include "ash/common/wm/immersive/wm_immersive_fullscreen_controller_delegate.h"
#include "ash/common/wm/window_state.h"
......@@ -25,12 +21,9 @@
#include "ash/common/wm_window.h"
#include "ash/common/wm_window_observer.h"
#include "ash/common/wm_window_property.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/view.h"
#include "ui/views/view_targeter.h"
#include "ui/views/widget/widget.h"
......@@ -116,257 +109,6 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate,
} // namespace
///////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh::HeaderView
// View which paints the header. It slides off and on screen in immersive
// fullscreen.
class CustomFrameViewAsh::HeaderView
: public views::View,
public WmImmersiveFullscreenControllerDelegate,
public ShellObserver {
public:
// |frame| is the widget that the caption buttons act on.
explicit HeaderView(views::Widget* frame);
~HeaderView() override;
// Schedules a repaint for the entire title.
void SchedulePaintForTitle();
// Tells the window controls to reset themselves to the normal state.
void ResetWindowControls();
// Returns the amount of the view's pixels which should be on screen.
int GetPreferredOnScreenHeight() const;
// Returns the view's preferred height.
int GetPreferredHeight() const;
// Returns the view's minimum width.
int GetMinimumWidth() const;
void UpdateAvatarIcon();
void SizeConstraintsChanged();
void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color);
// views::View:
void Layout() override;
void OnPaint(gfx::Canvas* canvas) override;
void ChildPreferredSizeChanged(views::View* child) override;
// ShellObserver:
void OnOverviewModeStarting() override;
void OnOverviewModeEnded() override;
void OnMaximizeModeStarted() override;
void OnMaximizeModeEnded() override;
FrameCaptionButtonContainerView* caption_button_container() {
return caption_button_container_;
}
views::View* avatar_icon() const { return avatar_icon_; }
private:
// WmImmersiveFullscreenControllerDelegate:
void OnImmersiveRevealStarted() override;
void OnImmersiveRevealEnded() override;
void OnImmersiveFullscreenExited() override;
void SetVisibleFraction(double visible_fraction) override;
std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override;
// The widget that the caption buttons act on.
views::Widget* frame_;
// Helper for painting the header.
std::unique_ptr<DefaultHeaderPainter> header_painter_;
views::ImageView* avatar_icon_;
// View which contains the window caption buttons.
FrameCaptionButtonContainerView* caption_button_container_;
// The fraction of the header's height which is visible while in fullscreen.
// This value is meaningless when not in fullscreen.
double fullscreen_visible_fraction_;
DISALLOW_COPY_AND_ASSIGN(HeaderView);
};
CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
: frame_(frame),
header_painter_(new DefaultHeaderPainter),
avatar_icon_(NULL),
caption_button_container_(NULL),
fullscreen_visible_fraction_(0) {
caption_button_container_ = new FrameCaptionButtonContainerView(frame_);
caption_button_container_->UpdateSizeButtonVisibility();
AddChildView(caption_button_container_);
header_painter_->Init(frame_, this, caption_button_container_);
UpdateAvatarIcon();
WmShell::Get()->AddShellObserver(this);
}
CustomFrameViewAsh::HeaderView::~HeaderView() {
WmShell::Get()->RemoveShellObserver(this);
}
void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() {
header_painter_->SchedulePaintForTitle();
}
void CustomFrameViewAsh::HeaderView::ResetWindowControls() {
caption_button_container_->ResetWindowControls();
}
int CustomFrameViewAsh::HeaderView::GetPreferredOnScreenHeight() const {
if (frame_->IsFullscreen()) {
return static_cast<int>(GetPreferredHeight() *
fullscreen_visible_fraction_);
}
return GetPreferredHeight();
}
int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const {
return header_painter_->GetHeaderHeightForPainting();
}
int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const {
return header_painter_->GetMinimumHeaderWidth();
}
void CustomFrameViewAsh::HeaderView::UpdateAvatarIcon() {
SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
WmWindow* window = WmLookup::Get()->GetWindowForWidget(frame_);
bool show = delegate->ShouldShowAvatar(window);
if (!show) {
if (!avatar_icon_)
return;
delete avatar_icon_;
avatar_icon_ = NULL;
} 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 CustomFrameViewAsh::HeaderView::SizeConstraintsChanged() {
caption_button_container_->ResetWindowControls();
caption_button_container_->UpdateSizeButtonVisibility();
Layout();
}
void CustomFrameViewAsh::HeaderView::SetFrameColors(
SkColor active_frame_color,
SkColor inactive_frame_color) {
header_painter_->SetFrameColors(active_frame_color, inactive_frame_color);
}
///////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh::HeaderView, views::View overrides:
void CustomFrameViewAsh::HeaderView::Layout() {
header_painter_->LayoutHeader();
}
void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) {
bool paint_as_active =
frame_->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 CustomFrameViewAsh::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();
}
///////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh::HeaderView, ShellObserver overrides:
void CustomFrameViewAsh::HeaderView::OnOverviewModeStarting() {
if (MaterialDesignController::IsOverviewMaterial())
caption_button_container_->SetVisible(false);
}
void CustomFrameViewAsh::HeaderView::OnOverviewModeEnded() {
if (MaterialDesignController::IsOverviewMaterial())
caption_button_container_->SetVisible(true);
}
void CustomFrameViewAsh::HeaderView::OnMaximizeModeStarted() {
caption_button_container_->UpdateSizeButtonVisibility();
parent()->Layout();
}
void CustomFrameViewAsh::HeaderView::OnMaximizeModeEnded() {
caption_button_container_->UpdateSizeButtonVisibility();
parent()->Layout();
}
///////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh::HeaderView,
// WmImmersiveFullscreenControllerDelegate overrides:
void CustomFrameViewAsh::HeaderView::OnImmersiveRevealStarted() {
fullscreen_visible_fraction_ = 0;
SetPaintToLayer(true);
layer()->SetFillsBoundsOpaquely(false);
parent()->Layout();
}
void CustomFrameViewAsh::HeaderView::OnImmersiveRevealEnded() {
fullscreen_visible_fraction_ = 0;
SetPaintToLayer(false);
parent()->Layout();
}
void CustomFrameViewAsh::HeaderView::OnImmersiveFullscreenExited() {
fullscreen_visible_fraction_ = 0;
SetPaintToLayer(false);
parent()->Layout();
}
void CustomFrameViewAsh::HeaderView::SetVisibleFraction(
double visible_fraction) {
if (fullscreen_visible_fraction_ != visible_fraction) {
fullscreen_visible_fraction_ = visible_fraction;
parent()->Layout();
}
}
std::vector<gfx::Rect>
CustomFrameViewAsh::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;
}
///////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh::OverlayView
......
......@@ -12,16 +12,16 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/views/window/non_client_view.h"
namespace ash {
class FrameCaptionButtonContainerView;
class WmImmersiveFullscreenController;
}
namespace views {
class Widget;
}
namespace ash {
class FrameCaptionButtonContainerView;
class HeaderView;
class WmImmersiveFullscreenController;
// A NonClientFrameView used for packaged apps, dialogs and other non-browser
// windows. It supports immersive fullscreen. When in immersive fullscreen, the
// client view takes up the entire widget and the window header is an overlay.
......@@ -92,7 +92,6 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView {
views::Widget* frame_;
// View which contains the title and window controls.
class HeaderView;
HeaderView* header_view_;
DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAsh);
......
// 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
// 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.
#ifndef ASH_COMMON_FRAME_HEADER_VIEW_H_
#define ASH_COMMON_FRAME_HEADER_VIEW_H_
#include <memory>
#include "ash/ash_export.h"
#include "ash/common/shell_observer.h"
#include "ash/common/wm/immersive/wm_immersive_fullscreen_controller_delegate.h"
#include "base/macros.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/views/view.h"
namespace views {
class ImageView;
class Widget;
}
namespace ash {
class DefaultHeaderPainter;
class FrameCaptionButtonContainerView;
// View which paints the frame header (title, caption buttons...). It slides off
// and on screen in immersive fullscreen.
class ASH_EXPORT HeaderView : public views::View,
public WmImmersiveFullscreenControllerDelegate,
public ShellObserver {
public:
// |target_widget| is the widget that the caption buttons act on.
// |target_widget| is not necessarily the same as the widget the header is
// placed in. For example, in immersive fullscreen this view may be painted in
// a widget that slides in and out on top of the main app or browser window.
// However, clicking a caption button should act on the target widget.
explicit HeaderView(views::Widget* target_widget);
~HeaderView() override;
// Schedules a repaint for the entire title.
void SchedulePaintForTitle();
// Tells the window controls to reset themselves to the normal state.
void ResetWindowControls();
// Returns the amount of the view's pixels which should be on screen.
int GetPreferredOnScreenHeight() const;
// Returns the view's preferred height.
int GetPreferredHeight() const;
// Returns the view's minimum width.
int GetMinimumWidth() const;
void UpdateAvatarIcon();
void SizeConstraintsChanged();
void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color);
// views::View:
void Layout() override;
void OnPaint(gfx::Canvas* canvas) override;
void ChildPreferredSizeChanged(views::View* child) override;
// ShellObserver:
void OnOverviewModeStarting() override;
void OnOverviewModeEnded() override;
void OnMaximizeModeStarted() override;
void OnMaximizeModeEnded() override;
FrameCaptionButtonContainerView* caption_button_container() {
return caption_button_container_;
}
views::View* avatar_icon() const;
private:
// WmImmersiveFullscreenControllerDelegate:
void OnImmersiveRevealStarted() override;
void OnImmersiveRevealEnded() override;
void OnImmersiveFullscreenExited() override;
void SetVisibleFraction(double visible_fraction) override;
std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override;
// The widget that the caption buttons act on.
views::Widget* target_widget_;
// Helper for painting the header.
std::unique_ptr<DefaultHeaderPainter> header_painter_;
views::ImageView* avatar_icon_;
// View which contains the window caption buttons.
FrameCaptionButtonContainerView* caption_button_container_;
// The fraction of the header's height which is visible while in fullscreen.
// This value is meaningless when not in fullscreen.
double fullscreen_visible_fraction_;
DISALLOW_COPY_AND_ASSIGN(HeaderView);
};
} // namespace ash
#endif // ASH_COMMON_FRAME_HEADER_VIEW_H_
......@@ -15,7 +15,7 @@ class Rect;
namespace ash {
class WmImmersiveFullscreenControllerDelegate {
class ASH_EXPORT WmImmersiveFullscreenControllerDelegate {
public:
// Called when a reveal of the top-of-window views starts.
virtual void OnImmersiveRevealStarted() = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment