Skip to content

Commit

Permalink
Handle titlebar text updates properly
Browse files Browse the repository at this point in the history
Previously the area of the text was not invalidated prior to the title drawing. As such all kind of results were possible.

BUG=152597, 151827
TEST=visual

Review URL: https://codereview.chromium.org/10993087

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159494 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
skuhne@google.com committed Oct 1, 2012
1 parent 3989e17 commit e213ff9
Show file tree
Hide file tree
Showing 29 changed files with 102 additions and 18 deletions.
4 changes: 4 additions & 0 deletions ash/wm/custom_frame_view_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ void CustomFrameViewAsh::UpdateWindowIcon() {
window_icon_->SchedulePaint();
}

void CustomFrameViewAsh::UpdateWindowTitle() {
frame_painter_->SchedulePaintForTitle(this, GetTitleFont());
}

////////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh, views::View overrides:

Expand Down
1 change: 1 addition & 0 deletions ash/wm/custom_frame_view_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// views::View overrides:
virtual gfx::Size GetPreferredSize() OVERRIDE;
Expand Down
4 changes: 4 additions & 0 deletions ash/wm/dialog_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ void DialogFrameView::UpdateWindowIcon() {
// Nothing to do.
}

void DialogFrameView::UpdateWindowTitle() {
// Nothing to do.
}

////////////////////////////////////////////////////////////////////////////////
// DialogFrameView, views::View overrides:

Expand Down
1 change: 1 addition & 0 deletions ash/wm/dialog_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DialogFrameView : public views::NonClientFrameView,
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// Overridden from View:
virtual std::string GetClassName() const OVERRIDE;
Expand Down
31 changes: 21 additions & 10 deletions ash/wm/frame_painter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,7 @@ void FramePainter::PaintTitleBar(views::NonClientFrameView* view,
// The window icon is painted by its own views::View.
views::WidgetDelegate* delegate = frame_->widget_delegate();
if (delegate && delegate->ShouldShowWindowTitle()) {
int title_x = GetTitleOffsetX();
// Center the text in the middle of the caption - this way it adapts
// automatically to the caption height (which is given by the owner).
int title_y =
(view->GetBoundsForClientView().y() - title_font.GetHeight()) / 2;
gfx::Rect title_bounds(
title_x,
std::max(0, title_y),
std::max(0, size_button_->x() - kTitleLogoSpacing - title_x),
title_font.GetHeight());
gfx::Rect title_bounds = GetTitleBounds(view, title_font);
canvas->DrawStringInt(delegate->GetWindowTitle(),
title_font,
kTitleTextColor,
Expand Down Expand Up @@ -533,6 +524,12 @@ void FramePainter::LayoutHeader(views::NonClientFrameView* view,
gfx::Rect(kIconOffsetX, kIconOffsetY, kIconSize, kIconSize));
}

void FramePainter::SchedulePaintForTitle(views::NonClientFrameView* view,
const gfx::Font& title_font) {
frame_->non_client_view()->SchedulePaintInRect(
GetTitleBounds(view, title_font));
}

///////////////////////////////////////////////////////////////////////////////
// aura::WindowObserver overrides:

Expand Down Expand Up @@ -736,4 +733,18 @@ void FramePainter::SchedulePaintForHeader() {
std::max(top_left_height, top_right_height)));
}

gfx::Rect FramePainter::GetTitleBounds(views::NonClientFrameView* view,
const gfx::Font& title_font) {
int title_x = GetTitleOffsetX();
// Center the text in the middle of the caption - this way it adapts
// automatically to the caption height (which is given by the owner).
int title_y =
(view->GetBoundsForClientView().y() - title_font.GetHeight()) / 2;
return gfx::Rect(
title_x,
std::max(0, title_y),
std::max(0, size_button_->x() - kTitleLogoSpacing - title_x),
title_font.GetHeight());
}

} // namespace ash
9 changes: 9 additions & 0 deletions ash/wm/frame_painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class ASH_EXPORT FramePainter : public aura::WindowObserver,
// not always.
void LayoutHeader(views::NonClientFrameView* view, bool shorter_layout);

// Schedule a re-paint of the entire title.
void SchedulePaintForTitle(views::NonClientFrameView* view,
const gfx::Font& title_font);

// aura::WindowObserver overrides:
virtual void OnWindowPropertyChanged(aura::Window* window,
const void* key,
Expand Down Expand Up @@ -162,6 +166,11 @@ class ASH_EXPORT FramePainter : public aura::WindowObserver,
// a header (or other way around).
void SchedulePaintForHeader();

// Get the bounds for the title. The provided |view| and |title_font| are
// used to determine the correct dimensions.
gfx::Rect GetTitleBounds(views::NonClientFrameView* view,
const gfx::Font& title_font);

static std::set<FramePainter*>* instances_;

// Not owned
Expand Down
4 changes: 4 additions & 0 deletions ash/wm/panel_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ void PanelFrameView::UpdateWindowIcon() {
NOTIMPLEMENTED();
}

void PanelFrameView::UpdateWindowTitle() {
NOTIMPLEMENTED();
}

void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) {
// Nothing.
}
Expand Down
1 change: 1 addition & 0 deletions ash/wm/panel_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ASH_EXPORT PanelFrameView : public views::NonClientFrameView,
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// Overridden from views::View:
virtual void Layout() OVERRIDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ void BrowserNonClientFrameViewAsh::UpdateWindowIcon() {
window_icon_->SchedulePaint();
}

void BrowserNonClientFrameViewAsh::UpdateWindowTitle() {
if (!frame()->IsFullscreen())
frame_painter_->SchedulePaintForTitle(this, BrowserFrame::GetTitleFont());
}

///////////////////////////////////////////////////////////////////////////////
// views::View overrides:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BrowserNonClientFrameViewAsh
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// views::View overrides:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/constrained_window_frame_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ConstrainedWindowFrameSimple : public views::NonClientFrameView {
gfx::Path* window_mask) OVERRIDE {}
virtual void ResetWindowControls() OVERRIDE {}
virtual void UpdateWindowIcon() OVERRIDE {}
virtual void UpdateWindowTitle() OVERRIDE {}

DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameSimple);
};
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/extensions/shell_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ShellWindowFrameView : public views::NonClientFrameView,
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE {}
virtual void UpdateWindowIcon() OVERRIDE {}
virtual void UpdateWindowTitle() OVERRIDE {}

// views::View implementation.
virtual gfx::Size GetPreferredSize() OVERRIDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ void AppNonClientFrameViewAura::ResetWindowControls() {
void AppNonClientFrameViewAura::UpdateWindowIcon() {
}

void AppNonClientFrameViewAura::UpdateWindowTitle() {
}

gfx::Rect AppNonClientFrameViewAura::GetBoundsForTabStrip(
views::View* tabstrip) const {
return gfx::Rect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AppNonClientFrameViewAura : public BrowserNonClientFrameView {
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// BrowserNonClientFrameView:
virtual gfx::Rect GetBoundsForTabStrip(
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/ui/views/frame/glass_browser_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class GlassBrowserFrameView : public BrowserNonClientFrameView,
const gfx::Rect& client_bounds) const OVERRIDE;
virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask)
OVERRIDE { }
virtual void ResetWindowControls() OVERRIDE { }
virtual void UpdateWindowIcon() OVERRIDE { }
OVERRIDE {}
virtual void ResetWindowControls() OVERRIDE {}
virtual void UpdateWindowIcon() OVERRIDE {}
virtual void UpdateWindowTitle() OVERRIDE {}

protected:
// Overridden from views::View:
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ui/views/frame/opaque_browser_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ void OpaqueBrowserFrameView::UpdateWindowIcon() {
window_icon_->SchedulePaint();
}

void OpaqueBrowserFrameView::UpdateWindowTitle() {
if (!frame()->IsFullscreen())
window_title_->SchedulePaint();
}

///////////////////////////////////////////////////////////////////////////////
// OpaqueBrowserFrameView, views::View overrides:

Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/frame/opaque_browser_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// Overridden from views::View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ui/views/frame/popup_non_client_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void PopupNonClientFrameView::ResetWindowControls() {
void PopupNonClientFrameView::UpdateWindowIcon() {
}

void PopupNonClientFrameView::UpdateWindowTitle() {
}

gfx::Rect PopupNonClientFrameView::GetBoundsForTabStrip(
views::View* tabstrip) const {
return gfx::Rect(0, 0, width(), tabstrip->GetPreferredSize().height());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PopupNonClientFrameView : public BrowserNonClientFrameView {
OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// BrowserNonClientFrameView:
virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE;
Expand Down
6 changes: 5 additions & 1 deletion chrome/browser/ui/views/panels/panel_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void PanelFrameView::Init() {
}

void PanelFrameView::UpdateTitle() {
title_label_->SetText(panel_view_->panel()->GetWindowTitle());
UpdateWindowTitle();
}

void PanelFrameView::UpdateIcon() {
Expand Down Expand Up @@ -340,6 +340,10 @@ void PanelFrameView::UpdateWindowIcon() {
title_icon_->SchedulePaint();
}

void PanelFrameView::UpdateWindowTitle() {
title_label_->SetText(panel_view_->panel()->GetWindowTitle());
}

gfx::Size PanelFrameView::GetPreferredSize() {
gfx::Size pref_size =
panel_view_->window()->client_view()->GetPreferredSize();
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/panels/panel_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class PanelFrameView : public views::NonClientFrameView,
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// Overridden from views::View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
Expand Down
1 change: 1 addition & 0 deletions ui/views/bubble/bubble_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView {
gfx::Path* window_mask) OVERRIDE {}
virtual void ResetWindowControls() OVERRIDE {}
virtual void UpdateWindowIcon() OVERRIDE {}
virtual void UpdateWindowTitle() OVERRIDE {}

// View overrides:
virtual gfx::Size GetPreferredSize() OVERRIDE;
Expand Down
9 changes: 5 additions & 4 deletions ui/views/widget/widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,6 @@ void Widget::UpdateWindowTitle() {
if (!non_client_view_)
return;

// If the non-client view is rendering its own title, it'll need to relayout
// now.
non_client_view_->Layout();

// Update the native frame's text. We do this regardless of whether or not
// the native frame is being used, since this also updates the taskbar, etc.
string16 window_title;
Expand All @@ -750,6 +746,11 @@ void Widget::UpdateWindowTitle() {
}
base::i18n::AdjustStringForLocaleDirection(&window_title);
native_widget_->SetWindowTitle(window_title);
non_client_view_->UpdateWindowTitle();

// If the non-client view is rendering its own title, it'll need to relayout
// now and to get a paint update later on.
non_client_view_->Layout();
}

void Widget::UpdateWindowIcon() {
Expand Down
4 changes: 4 additions & 0 deletions ui/views/window/custom_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ void CustomFrameView::UpdateWindowIcon() {
window_icon_->SchedulePaint();
}

void CustomFrameView::UpdateWindowTitle() {
SchedulePaintInRect(title_bounds_);
}

///////////////////////////////////////////////////////////////////////////////
// CustomFrameView, View overrides:

Expand Down
1 change: 1 addition & 0 deletions ui/views/window/custom_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CustomFrameView : public NonClientFrameView,
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// Overridden from View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
Expand Down
4 changes: 4 additions & 0 deletions ui/views/window/native_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void NativeFrameView::UpdateWindowIcon() {
// Nothing to do.
}

void NativeFrameView::UpdateWindowTitle() {
// Nothing to do.
}

gfx::Size NativeFrameView::GetPreferredSize() {
return frame_->client_view()->GetPreferredSize();
}
Expand Down
1 change: 1 addition & 0 deletions ui/views/window/native_frame_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class VIEWS_EXPORT NativeFrameView : public NonClientFrameView {
gfx::Path* window_mask) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
virtual void UpdateWindowTitle() OVERRIDE;

// View overrides:

Expand Down
4 changes: 4 additions & 0 deletions ui/views/window/non_client_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ void NonClientView::UpdateWindowIcon() {
frame_view_->UpdateWindowIcon();
}

void NonClientView::UpdateWindowTitle() {
frame_view_->UpdateWindowTitle();
}

void NonClientView::LayoutFrameView() {
// First layout the NonClientFrameView, which determines the size of the
// ClientView...
Expand Down
5 changes: 5 additions & 0 deletions ui/views/window/non_client_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class VIEWS_EXPORT NonClientFrameView : public View {
gfx::Path* window_mask) = 0;
virtual void ResetWindowControls() = 0;
virtual void UpdateWindowIcon() = 0;
virtual void UpdateWindowTitle() = 0;

// Overridden from View:
virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
Expand Down Expand Up @@ -184,6 +185,10 @@ class VIEWS_EXPORT NonClientView : public View {
// Tells the NonClientView to invalidate the NonClientFrameView's window icon.
void UpdateWindowIcon();

// Tells the NonClientView to invalidate the NonClientFrameView's window
// title.
void UpdateWindowTitle();

// Get/Set client_view property.
ClientView* client_view() const { return client_view_; }
void set_client_view(ClientView* client_view) {
Expand Down

0 comments on commit e213ff9

Please sign in to comment.