This source file includes following definitions.
- frame_border_hit_test_controller_
- Init
- GetBoundsForTabStrip
- GetTopInset
- GetThemeBackgroundXInset
- UpdateThrobber
- GetBoundsForClientView
- GetWindowBoundsForClientBounds
- NonClientHitTest
- GetWindowMask
- ResetWindowControls
- UpdateWindowIcon
- UpdateWindowTitle
- OnPaint
- Layout
- GetClassName
- HitTestRect
- GetAccessibleState
- GetMinimumSize
- OnMaximizeModeStarted
- OnMaximizeModeEnded
- ShouldTabIconViewAnimate
- GetFaviconForTabIconView
- GetTabStripLeftInset
- GetTabStripRightInset
- UseImmersiveLightbarHeaderStyle
- UsePackagedAppHeaderStyle
- LayoutAvatar
- ShouldPaint
- PaintImmersiveLightbarStyleHeader
- PaintToolbarBackground
- PaintContentEdge
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h"
#include "ash/ash_switches.h"
#include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/frame/default_header_painter.h"
#include "ash/frame/frame_border_hit_test_controller.h"
#include "ash/frame/header_painter_util.h"
#include "ash/shell.h"
#include "base/command_line.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/avatar_label.h"
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_header_painter_ash.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/tab_icon_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/web_contents.h"
#include "grit/ash_resources.h"
#include "grit/theme_resources.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h"
#include "ui/compositor/layer_animator.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/layout_constants.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace {
const int kAvatarBottomSpacing = 2;
const int kAvatarSideSpacing = 2;
const int kTabstripLeftSpacing = 0;
const int kTabstripRightSpacing = 10;
const int kContentShadowHeight = 1;
const int kTabstripTopSpacingTall = 7;
const int kTabstripTopSpacingShort = 0;
const int kTabShadowHeight = 4;
}
const char BrowserNonClientFrameViewAsh::kViewClassName[] =
"BrowserNonClientFrameViewAsh";
BrowserNonClientFrameViewAsh::BrowserNonClientFrameViewAsh(
BrowserFrame* frame, BrowserView* browser_view)
: BrowserNonClientFrameView(frame, browser_view),
caption_button_container_(NULL),
window_icon_(NULL),
frame_border_hit_test_controller_(
new ash::FrameBorderHitTestController(frame)) {
ash::Shell::GetInstance()->AddShellObserver(this);
}
BrowserNonClientFrameViewAsh::~BrowserNonClientFrameViewAsh() {
ash::Shell::GetInstance()->RemoveShellObserver(this);
}
void BrowserNonClientFrameViewAsh::Init() {
caption_button_container_ = new ash::FrameCaptionButtonContainerView(frame(),
ash::FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
caption_button_container_->UpdateSizeButtonVisibility(
ash::Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled());
AddChildView(caption_button_container_);
if (browser_view()->ShouldShowWindowIcon()) {
window_icon_ = new TabIconView(this, NULL);
window_icon_->set_is_light(true);
AddChildView(window_icon_);
window_icon_->Update();
}
UpdateAvatarInfo();
if (UsePackagedAppHeaderStyle()) {
ash::DefaultHeaderPainter* header_painter = new ash::DefaultHeaderPainter;
header_painter_.reset(header_painter);
header_painter->Init(frame(), this, window_icon_,
caption_button_container_);
} else {
BrowserHeaderPainterAsh* header_painter = new BrowserHeaderPainterAsh;
header_painter_.reset(header_painter);
header_painter->Init(frame(), browser_view(), this, window_icon_,
caption_button_container_);
}
}
gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForTabStrip(
views::View* tabstrip) const {
if (!tabstrip)
return gfx::Rect();
int left_inset = GetTabStripLeftInset();
int right_inset = GetTabStripRightInset();
return gfx::Rect(left_inset,
GetTopInset(),
std::max(0, width() - left_inset - right_inset),
tabstrip->GetPreferredSize().height());
}
int BrowserNonClientFrameViewAsh::GetTopInset() const {
if (!ShouldPaint() || UseImmersiveLightbarHeaderStyle())
return 0;
if (browser_view()->IsTabStripVisible()) {
if (frame()->IsMaximized() || frame()->IsFullscreen())
return kTabstripTopSpacingShort;
else
return kTabstripTopSpacingTall;
}
if (UsePackagedAppHeaderStyle())
return header_painter_->GetHeaderHeightForPainting();
int caption_buttons_bottom = caption_button_container_->bounds().bottom();
if (browser_view()->IsToolbarVisible())
return caption_buttons_bottom - kContentShadowHeight;
return caption_buttons_bottom + kClientEdgeThickness;
}
int BrowserNonClientFrameViewAsh::GetThemeBackgroundXInset() const {
return ash::HeaderPainterUtil::GetThemeBackgroundXInset();
}
void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) {
if (window_icon_)
window_icon_->Update();
}
gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForClientView() const {
return bounds();
}
gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const {
return client_bounds;
}
int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) {
int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this,
caption_button_container_, point);
if (hit_test == HTCAPTION && ((avatar_button() &&
avatar_button()->GetMirroredBounds().Contains(point)) ||
(avatar_label() && avatar_label()->GetMirroredBounds().Contains(point))))
return HTCLIENT;
if (hit_test == HTCLIENT &&
!(frame()->IsMaximized() || frame()->IsFullscreen())) {
gfx::Point client_point(point);
View::ConvertPointToTarget(this, frame()->client_view(), &client_point);
gfx::Rect tabstrip_bounds(browser_view()->tabstrip()->bounds());
if (client_point.y() < tabstrip_bounds.y() + kTabShadowHeight)
hit_test = HTCAPTION;
}
return hit_test;
}
void BrowserNonClientFrameViewAsh::GetWindowMask(const gfx::Size& size,
gfx::Path* window_mask) {
}
void BrowserNonClientFrameViewAsh::ResetWindowControls() {
bool button_visibility = !UseImmersiveLightbarHeaderStyle();
caption_button_container_->SetVisible(button_visibility);
caption_button_container_->ResetWindowControls();
}
void BrowserNonClientFrameViewAsh::UpdateWindowIcon() {
if (window_icon_)
window_icon_->SchedulePaint();
}
void BrowserNonClientFrameViewAsh::UpdateWindowTitle() {
if (!frame()->IsFullscreen())
header_painter_->SchedulePaintForTitle();
}
void BrowserNonClientFrameViewAsh::OnPaint(gfx::Canvas* canvas) {
if (!ShouldPaint())
return;
if (UseImmersiveLightbarHeaderStyle()) {
PaintImmersiveLightbarStyleHeader(canvas);
return;
}
caption_button_container_->SetPaintAsActive(ShouldPaintAsActive());
ash::HeaderPainter::Mode header_mode = ShouldPaintAsActive() ?
ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE;
header_painter_->PaintHeader(canvas, header_mode);
if (browser_view()->IsToolbarVisible())
PaintToolbarBackground(canvas);
else if (!UsePackagedAppHeaderStyle())
PaintContentEdge(canvas);
}
void BrowserNonClientFrameViewAsh::Layout() {
header_painter_->LayoutHeader();
int painted_height = 0;
if (browser_view()->IsTabStripVisible()) {
painted_height = GetTopInset() +
browser_view()->tabstrip()->GetPreferredSize().height();
} else if (browser_view()->IsToolbarVisible()) {
painted_height = GetTopInset() + kFrameShadowThickness * 2;
} else {
painted_height = GetTopInset();
}
header_painter_->SetHeaderHeightForPainting(painted_height);
if (avatar_button())
LayoutAvatar();
BrowserNonClientFrameView::Layout();
}
const char* BrowserNonClientFrameViewAsh::GetClassName() const {
return kViewClassName;
}
bool BrowserNonClientFrameViewAsh::HitTestRect(const gfx::Rect& rect) const {
if (!views::View::HitTestRect(rect)) {
return false;
}
TabStrip* tabstrip = browser_view()->tabstrip();
if (tabstrip && browser_view()->IsTabStripVisible()) {
gfx::RectF rect_in_tabstrip_coords_f(rect);
View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
rect_in_tabstrip_coords_f);
if (rect_in_tabstrip_coords.y() > tabstrip->height())
return false;
return !tabstrip->HitTestRect(rect_in_tabstrip_coords) ||
tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
}
return rect.y() < GetTopInset();
}
void BrowserNonClientFrameViewAsh::GetAccessibleState(
ui::AXViewState* state) {
state->role = ui::AX_ROLE_TITLE_BAR;
}
gfx::Size BrowserNonClientFrameViewAsh::GetMinimumSize() {
gfx::Size min_client_view_size(frame()->client_view()->GetMinimumSize());
int min_width = std::max(header_painter_->GetMinimumHeaderWidth(),
min_client_view_size.width());
if (browser_view()->IsTabStripVisible()) {
int min_tabstrip_width =
browser_view()->tabstrip()->GetMinimumSize().width();
min_width = std::max(min_width,
min_tabstrip_width + GetTabStripLeftInset() + GetTabStripRightInset());
}
return gfx::Size(min_width, min_client_view_size.height());
}
void BrowserNonClientFrameViewAsh::OnMaximizeModeStarted() {
caption_button_container_->UpdateSizeButtonVisibility(true);
InvalidateLayout();
frame()->client_view()->InvalidateLayout();
frame()->GetRootView()->Layout();
}
void BrowserNonClientFrameViewAsh::OnMaximizeModeEnded() {
caption_button_container_->UpdateSizeButtonVisibility(false);
InvalidateLayout();
frame()->client_view()->InvalidateLayout();
frame()->GetRootView()->Layout();
}
bool BrowserNonClientFrameViewAsh::ShouldTabIconViewAnimate() const {
content::WebContents* current_tab = browser_view()->GetActiveWebContents();
return current_tab ? current_tab->IsLoading() : false;
}
gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() {
views::WidgetDelegate* delegate = frame()->widget_delegate();
if (!delegate)
return gfx::ImageSkia();
return delegate->GetWindowIcon();
}
int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const {
return avatar_button() ? kAvatarSideSpacing +
browser_view()->GetOTRAvatarIcon().width() + kAvatarSideSpacing :
kTabstripLeftSpacing;
}
int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const {
return caption_button_container_->GetPreferredSize().width() +
kTabstripRightSpacing;
}
bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const {
ImmersiveModeController* immersive_controller =
browser_view()->immersive_mode_controller();
return immersive_controller->IsEnabled() &&
!immersive_controller->IsRevealed() &&
browser_view()->IsTabStripVisible();
}
bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const {
return browser_view()->browser()->is_app() &&
!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableStreamlinedHostedApps);
}
void BrowserNonClientFrameViewAsh::LayoutAvatar() {
DCHECK(avatar_button());
#if !defined(OS_CHROMEOS)
DCHECK(browser_view()->IsTabStripVisible());
#endif
gfx::ImageSkia incognito_icon = browser_view()->GetOTRAvatarIcon();
int avatar_bottom = GetTopInset() +
browser_view()->GetTabStripHeight() - kAvatarBottomSpacing;
int avatar_restored_y = avatar_bottom - incognito_icon.height();
int avatar_y =
(browser_view()->IsTabStripVisible() &&
(frame()->IsMaximized() || frame()->IsFullscreen())) ?
GetTopInset() + kContentShadowHeight : avatar_restored_y;
bool avatar_visible = !UseImmersiveLightbarHeaderStyle();
int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0;
gfx::Rect avatar_bounds(kAvatarSideSpacing,
avatar_y,
incognito_icon.width(),
avatar_height);
avatar_button()->SetBoundsRect(avatar_bounds);
avatar_button()->SetVisible(avatar_visible);
}
bool BrowserNonClientFrameViewAsh::ShouldPaint() const {
if (!frame()->IsFullscreen())
return true;
ImmersiveModeController* immersive_mode_controller =
browser_view()->immersive_mode_controller();
return immersive_mode_controller->IsEnabled() &&
(immersive_mode_controller->IsRevealed() ||
UseImmersiveLightbarHeaderStyle());
}
void BrowserNonClientFrameViewAsh::PaintImmersiveLightbarStyleHeader(
gfx::Canvas* canvas) {
gfx::ImageSkia* frame_image = GetThemeProvider()->GetImageSkiaNamed(
IDR_AURA_BROWSER_WINDOW_HEADER_BASE_MAXIMIZED);
canvas->TileImageInt(*frame_image, 0, 0, width(), frame_image->height());
}
void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) {
gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
if (toolbar_bounds.IsEmpty())
return;
gfx::Point toolbar_origin(toolbar_bounds.origin());
View::ConvertPointToTarget(browser_view(), this, &toolbar_origin);
toolbar_bounds.set_origin(toolbar_origin);
int x = toolbar_bounds.x();
int w = toolbar_bounds.width();
int y = toolbar_bounds.y();
int h = toolbar_bounds.height();
int split_point = kFrameShadowThickness * 2;
int bottom_y = y + split_point;
ui::ThemeProvider* tp = GetThemeProvider();
int bottom_edge_height = h - split_point;
canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height),
tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
canvas->TileImageInt(
*theme_toolbar,
x + GetThemeBackgroundXInset(),
bottom_y - GetTopInset(),
x, bottom_y,
w, theme_toolbar->height());
const int kContentShadowHeight = 2;
gfx::ImageSkia* toolbar_top = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP);
canvas->TileImageInt(*toolbar_top,
0, 0,
x, y - kContentShadowHeight,
w, split_point + kContentShadowHeight + 1);
gfx::ImageSkia* toolbar_left = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT);
canvas->TileImageInt(*toolbar_left,
0, 0,
x + kClientEdgeThickness,
y + kClientEdgeThickness + kContentShadowHeight,
toolbar_left->width(), theme_toolbar->height());
gfx::ImageSkia* toolbar_right =
tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT);
canvas->TileImageInt(*toolbar_right,
0, 0,
w - toolbar_right->width() - 2 * kClientEdgeThickness,
y + kClientEdgeThickness + kContentShadowHeight,
toolbar_right->width(), theme_toolbar->height());
canvas->FillRect(
gfx::Rect(x + kClientEdgeThickness,
toolbar_bounds.bottom() - kClientEdgeThickness,
w - (2 * kClientEdgeThickness),
kClientEdgeThickness),
ThemeProperties::GetDefaultColor(
ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
}
void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) {
DCHECK(!UsePackagedAppHeaderStyle());
canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(),
width(), kClientEdgeThickness),
ThemeProperties::GetDefaultColor(
ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
}