summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 04:35:48 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 04:35:48 +0000
commit2caba84bb84c0ee284626e5c3940c689dbe4f103 (patch)
tree9d392f268cd6b4364be11d5ffe37830626355751 /chrome/browser/views
parent59e0bfc9452c58f2955d71c7c0d77f4ecd0d8327 (diff)
downloadchromium_src-2caba84bb84c0ee284626e5c3940c689dbe4f103.zip
chromium_src-2caba84bb84c0ee284626e5c3940c689dbe4f103.tar.gz
chromium_src-2caba84bb84c0ee284626e5c3940c689dbe4f103.tar.bz2
Don't load the font for the window title if we're not going to be painting a text title bar... ie. don't load the font for the title bar for the main browser window since we won't use it - it's only used for app windows.
http://crbug.com/2369 Review URL: http://codereview.chromium.org/2919 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/browser_views.vcproj4
-rw-r--r--chrome/browser/views/constrained_window_impl.cc41
-rw-r--r--chrome/browser/views/frame/aero_glass_non_client_view.cc8
-rw-r--r--chrome/browser/views/frame/opaque_non_client_view.cc87
-rw-r--r--chrome/browser/views/frame/opaque_non_client_view.h5
-rw-r--r--chrome/browser/views/window_resources.cc27
-rw-r--r--chrome/browser/views/window_resources.h25
7 files changed, 66 insertions, 131 deletions
diff --git a/chrome/browser/views/browser_views.vcproj b/chrome/browser/views/browser_views.vcproj
index 6a36ee7..388f844 100644
--- a/chrome/browser/views/browser_views.vcproj
+++ b/chrome/browser/views/browser_views.vcproj
@@ -826,10 +826,6 @@
>
</File>
<File
- RelativePath=".\window_resources.cc"
- >
- </File>
- <File
RelativePath=".\window_resources.h"
>
</File>
diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc
index de02b41..4766ea3 100644
--- a/chrome/browser/views/constrained_window_impl.cc
+++ b/chrome/browser/views/constrained_window_impl.cc
@@ -90,8 +90,6 @@ class XPWindowResources : public WindowResources {
virtual SkBitmap* GetPartBitmap(FramePartBitmap part_id) const {
return bitmaps_[part_id];
}
- virtual const ChromeFont& GetTitleFont() const { return title_font_; }
- virtual SkColor GetTitleColor() const { return SK_ColorWHITE; }
private:
static void InitClass() {
@@ -103,14 +101,11 @@ class XPWindowResources : public WindowResources {
if (id != 0)
bitmaps_[i] = rb.GetBitmapNamed(id);
}
- title_font_ =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1);
initialized = true;
}
}
static SkBitmap* bitmaps_[FRAME_PART_BITMAP_COUNT];
- static ChromeFont title_font_;
DISALLOW_EVIL_CONSTRUCTORS(XPWindowResources);
};
@@ -125,8 +120,6 @@ class VistaWindowResources : public WindowResources {
virtual SkBitmap* GetPartBitmap(FramePartBitmap part_id) const {
return bitmaps_[part_id];
}
- virtual const ChromeFont& GetTitleFont() const { return title_font_; }
- virtual SkColor GetTitleColor() const { return SK_ColorBLACK; }
private:
static void InitClass() {
@@ -138,14 +131,11 @@ class VistaWindowResources : public WindowResources {
if (id != 0)
bitmaps_[i] = rb.GetBitmapNamed(id);
}
- title_font_ =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1);
initialized = true;
}
}
static SkBitmap* bitmaps_[FRAME_PART_BITMAP_COUNT];
- static ChromeFont title_font_;
DISALLOW_EVIL_CONSTRUCTORS(VistaWindowResources);
};
@@ -160,8 +150,6 @@ class OTRWindowResources : public WindowResources {
virtual SkBitmap* GetPartBitmap(FramePartBitmap part_id) const {
return bitmaps_[part_id];
}
- virtual const ChromeFont& GetTitleFont() const { return title_font_; }
- virtual SkColor GetTitleColor() const { return SK_ColorWHITE; }
private:
static void InitClass() {
@@ -173,24 +161,18 @@ class OTRWindowResources : public WindowResources {
if (id != 0)
bitmaps_[i] = rb.GetBitmapNamed(id);
}
- title_font_ =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1);
initialized = true;
}
}
static SkBitmap* bitmaps_[FRAME_PART_BITMAP_COUNT];
- static ChromeFont title_font_;
DISALLOW_EVIL_CONSTRUCTORS(OTRWindowResources);
};
SkBitmap* XPWindowResources::bitmaps_[];
-ChromeFont XPWindowResources::title_font_;
SkBitmap* VistaWindowResources::bitmaps_[];
-ChromeFont VistaWindowResources::title_font_;
SkBitmap* OTRWindowResources::bitmaps_[];
-ChromeFont OTRWindowResources::title_font_;
////////////////////////////////////////////////////////////////////////////////
// ConstrainedWindowNonClientView
@@ -263,6 +245,14 @@ class ConstrainedWindowNonClientView
void UpdateLocationBar();
bool ShouldDisplayURLField() const;
+ SkColor GetTitleColor() const {
+ if (container_->owner()->profile()->IsOffTheRecord() ||
+ win_util::ShouldUseVistaFrame()) {
+ return SK_ColorWHITE;
+ }
+ return SK_ColorBLACK;
+ }
+
ConstrainedWindowImpl* container_;
ChromeViews::WindowDelegate* window_delegate_;
@@ -318,11 +308,15 @@ class ConstrainedWindowNonClientView
// The number of animation frames in throbber_frames_.
static int throbber_frame_count_;
+ // The font to be used to render the titlebar text.
+ static ChromeFont title_font_;
+
DISALLOW_EVIL_CONSTRUCTORS(ConstrainedWindowNonClientView);
};
SkBitmap ConstrainedWindowNonClientView::throbber_frames_;
int ConstrainedWindowNonClientView::throbber_frame_count_ = -1;
+ChromeFont ConstrainedWindowNonClientView::title_font_;
static const int kWindowLeftSpacing = 5;
static const int kWindowControlsTopOffset = 1;
static const int kWindowControlsRightOffset = 4;
@@ -420,8 +414,7 @@ bool ConstrainedWindowNonClientView::ShouldDisplayURLField() const {
int ConstrainedWindowNonClientView::CalculateTitlebarHeight() const {
int height;
if (window_delegate_ && window_delegate_->ShouldShowWindowTitle()) {
- height = kTitleTopOffset + resources_->GetTitleFont().height() +
- kTitleBottomSpacing;
+ height = kTitleTopOffset + title_font_.height() + kTitleBottomSpacing;
} else {
height = kNoTitleTopSpacing;
}
@@ -609,8 +602,7 @@ void ConstrainedWindowNonClientView::Layout() {
int title_right = close_button_->GetX() - spacing;
int title_left = icon_bounds_.right() + spacing;
title_bounds_.SetRect(title_left, kTitleTopOffset,
- title_right - title_left,
- resources_->GetTitleFont().height());
+ title_right - title_left, title_font_.height());
}
}
@@ -764,9 +756,8 @@ void ConstrainedWindowNonClientView::PaintThrobber(ChromeCanvas* canvas) {
}
void ConstrainedWindowNonClientView::PaintWindowTitle(ChromeCanvas* canvas) {
- canvas->DrawStringInt(container_->GetWindowTitle(),
- resources_->GetTitleFont(),
- resources_->GetTitleColor(), title_bounds_.x(),
+ canvas->DrawStringInt(container_->GetWindowTitle(), title_font_,
+ GetTitleColor(), title_bounds_.x(),
title_bounds_.y(), title_bounds_.width(),
title_bounds_.height());
}
diff --git a/chrome/browser/views/frame/aero_glass_non_client_view.cc b/chrome/browser/views/frame/aero_glass_non_client_view.cc
index 5692a77..5a359b4 100644
--- a/chrome/browser/views/frame/aero_glass_non_client_view.cc
+++ b/chrome/browser/views/frame/aero_glass_non_client_view.cc
@@ -40,9 +40,6 @@ class AeroGlassWindowResources {
virtual SkBitmap* GetPartBitmap(FramePartBitmap part) const {
return standard_frame_bitmaps_[part];
}
- virtual const ChromeFont& GetTitleFont() const {
- return title_font_;
- }
SkBitmap app_top_left() const { return app_top_left_; }
SkBitmap app_top_center() const { return app_top_center_; }
@@ -67,9 +64,6 @@ class AeroGlassWindowResources {
if (id != 0)
standard_frame_bitmaps_[i] = rb.GetBitmapNamed(id);
}
- title_font_ =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1, ChromeFont::BOLD);
-
app_top_left_ = *rb.GetBitmapNamed(IDR_APP_TOP_LEFT);
app_top_center_ = *rb.GetBitmapNamed(IDR_APP_TOP_CENTER);
app_top_right_ = *rb.GetBitmapNamed(IDR_APP_TOP_RIGHT);
@@ -79,7 +73,6 @@ class AeroGlassWindowResources {
}
static SkBitmap* standard_frame_bitmaps_[FRAME_PART_BITMAP_COUNT];
- static ChromeFont title_font_;
static SkBitmap app_top_left_;
static SkBitmap app_top_center_;
static SkBitmap app_top_right_;
@@ -89,7 +82,6 @@ class AeroGlassWindowResources {
// static
SkBitmap* AeroGlassWindowResources::standard_frame_bitmaps_[];
-ChromeFont AeroGlassWindowResources::title_font_;
SkBitmap AeroGlassWindowResources::app_top_left_;
SkBitmap AeroGlassWindowResources::app_top_center_;
SkBitmap AeroGlassWindowResources::app_top_right_;
diff --git a/chrome/browser/views/frame/opaque_non_client_view.cc b/chrome/browser/views/frame/opaque_non_client_view.cc
index f10483b..6febf81 100644
--- a/chrome/browser/views/frame/opaque_non_client_view.cc
+++ b/chrome/browser/views/frame/opaque_non_client_view.cc
@@ -68,7 +68,6 @@ class ActiveWindowResources : public WindowResources {
public:
ActiveWindowResources() {
InitClass();
- WindowResources::InitClass();
}
virtual ~ActiveWindowResources() { }
@@ -76,9 +75,6 @@ class ActiveWindowResources : public WindowResources {
virtual SkBitmap* GetPartBitmap(FramePartBitmap part) const {
return standard_frame_bitmaps_[part];
}
- virtual const ChromeFont& GetTitleFont() const {
- return title_font_;
- }
private:
static void InitClass() {
@@ -109,8 +105,6 @@ class ActiveWindowResources : public WindowResources {
if (id != 0)
standard_frame_bitmaps_[i] = rb.GetBitmapNamed(id);
}
- title_font_ =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1, ChromeFont::BOLD);
initialized = true;
}
}
@@ -125,7 +119,6 @@ class InactiveWindowResources : public WindowResources {
public:
InactiveWindowResources() {
InitClass();
- WindowResources::InitClass();
}
virtual ~InactiveWindowResources() { }
@@ -133,9 +126,6 @@ class InactiveWindowResources : public WindowResources {
virtual SkBitmap* GetPartBitmap(FramePartBitmap part) const {
return standard_frame_bitmaps_[part];
}
- virtual const ChromeFont& GetTitleFont() const {
- return title_font_;
- }
private:
static void InitClass() {
@@ -166,8 +156,6 @@ class InactiveWindowResources : public WindowResources {
if (id != 0)
standard_frame_bitmaps_[i] = rb.GetBitmapNamed(id);
}
- title_font_ =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1, ChromeFont::BOLD);
initialized = true;
}
}
@@ -182,7 +170,6 @@ class OTRActiveWindowResources : public WindowResources {
public:
OTRActiveWindowResources() {
InitClass();
- WindowResources::InitClass();
}
virtual ~OTRActiveWindowResources() { }
@@ -190,10 +177,7 @@ class OTRActiveWindowResources : public WindowResources {
virtual SkBitmap* GetPartBitmap(FramePartBitmap part) const {
return standard_frame_bitmaps_[part];
}
- virtual const ChromeFont& GetTitleFont() const {
- return title_font_;
- }
-
+
private:
static void InitClass() {
static bool initialized = false;
@@ -223,14 +207,11 @@ class OTRActiveWindowResources : public WindowResources {
if (id != 0)
standard_frame_bitmaps_[i] = rb.GetBitmapNamed(id);
}
- title_font_ =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1, ChromeFont::BOLD);
initialized = true;
}
}
static SkBitmap* standard_frame_bitmaps_[FRAME_PART_BITMAP_COUNT];
- static ChromeFont title_font_;
DISALLOW_EVIL_CONSTRUCTORS(OTRActiveWindowResources);
};
@@ -239,7 +220,6 @@ class OTRInactiveWindowResources : public WindowResources {
public:
OTRInactiveWindowResources() {
InitClass();
- WindowResources::InitClass();
}
virtual ~OTRInactiveWindowResources() { }
@@ -247,9 +227,6 @@ class OTRInactiveWindowResources : public WindowResources {
virtual SkBitmap* GetPartBitmap(FramePartBitmap part) const {
return standard_frame_bitmaps_[part];
}
- virtual const ChromeFont& GetTitleFont() const {
- return title_font_;
- }
private:
static void InitClass() {
@@ -281,8 +258,6 @@ class OTRInactiveWindowResources : public WindowResources {
if (id != 0)
standard_frame_bitmaps_[i] = rb.GetBitmapNamed(id);
}
- title_font_ =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1, ChromeFont::BOLD);
initialized = true;
}
}
@@ -294,19 +269,19 @@ class OTRInactiveWindowResources : public WindowResources {
};
// static
SkBitmap* ActiveWindowResources::standard_frame_bitmaps_[];
-ChromeFont ActiveWindowResources::title_font_;
SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[];
-ChromeFont InactiveWindowResources::title_font_;
SkBitmap* OTRActiveWindowResources::standard_frame_bitmaps_[];
-ChromeFont OTRActiveWindowResources::title_font_;
SkBitmap* OTRInactiveWindowResources::standard_frame_bitmaps_[];
-ChromeFont OTRInactiveWindowResources::title_font_;
WindowResources* OpaqueNonClientView::active_resources_ = NULL;
WindowResources* OpaqueNonClientView::inactive_resources_ = NULL;
WindowResources* OpaqueNonClientView::active_otr_resources_ = NULL;
WindowResources* OpaqueNonClientView::inactive_otr_resources_ = NULL;
SkBitmap OpaqueNonClientView::distributor_logo_;
+SkBitmap OpaqueNonClientView::app_top_left_;
+SkBitmap OpaqueNonClientView::app_top_center_;
+SkBitmap OpaqueNonClientView::app_top_right_;
+ChromeFont OpaqueNonClientView::title_font_;
// The distance between the top of the window and the top of the window
// controls when the window is restored.
@@ -459,6 +434,10 @@ OpaqueNonClientView::OpaqueNonClientView(OpaqueFrame* frame,
AddChildView(window_icon_);
window_icon_->Update();
}
+ // Only load the title font if we're going to need to use it to paint.
+ // Loading fonts is expensive.
+ if (browser_view_->ShouldShowWindowTitle())
+ InitAppWindowResources();
}
OpaqueNonClientView::~OpaqueNonClientView() {
@@ -716,10 +695,8 @@ void OpaqueNonClientView::SetWindowIcon(SkBitmap window_icon) {
}
int OpaqueNonClientView::CalculateNonClientTopHeight() const {
- if (frame_->window_delegate()->ShouldShowWindowTitle()) {
- return kTitleTopOffset + resources()->GetTitleFont().height() +
- kTitleBottomSpacing;
- }
+ if (frame_->window_delegate()->ShouldShowWindowTitle())
+ return kTitleTopOffset + title_font_.height() + kTitleBottomSpacing;
return frame_->IsMaximized() ? kNoTitleZoomedTopSpacing : kNoTitleTopSpacing;
}
@@ -803,11 +780,9 @@ void OpaqueNonClientView::PaintTitleBar(ChromeCanvas* canvas) {
// The window icon is painted by the TabIconView.
ChromeViews::WindowDelegate* d = frame_->window_delegate();
if (d->ShouldShowWindowTitle()) {
- canvas->DrawStringInt(d->GetWindowTitle(),
- resources()->GetTitleFont(),
- resources()->GetTitleColor(), title_bounds_.x(),
- title_bounds_.y(), title_bounds_.width(),
- title_bounds_.height());
+ canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE,
+ title_bounds_.x(), title_bounds_.y(),
+ title_bounds_.width(), title_bounds_.height());
}
}
@@ -883,18 +858,15 @@ void OpaqueNonClientView::PaintClientEdge(ChromeCanvas* canvas) {
left->width(), client_area_bounds.height() - fudge);
if (frame_->window_delegate()->ShouldShowWindowTitle()) {
- SkBitmap app_top_left = resources()->app_top_left();
- SkBitmap app_top_center = resources()->app_top_center();
- SkBitmap app_top_right = resources()->app_top_right();
- canvas->DrawBitmapInt(app_top_left,
- client_area_bounds.x() - app_top_left.width(),
- client_area_bounds.y() - app_top_left.height() +
+ canvas->DrawBitmapInt(app_top_left_,
+ client_area_bounds.x() - app_top_left_.width(),
+ client_area_bounds.y() - app_top_left_.height() +
fudge);
- canvas->TileImageInt(app_top_center, client_area_bounds.x(),
- client_area_bounds.y() - app_top_center.height(),
- client_area_bounds.width(), app_top_center.height());
- canvas->DrawBitmapInt(app_top_right, client_area_bounds.right(),
- client_area_bounds.y() - app_top_right.height() +
+ canvas->TileImageInt(app_top_center_, client_area_bounds.x(),
+ client_area_bounds.y() - app_top_center_.height(),
+ client_area_bounds.width(), app_top_center_.height());
+ canvas->DrawBitmapInt(app_top_right_, client_area_bounds.right(),
+ client_area_bounds.y() - app_top_right_.height() +
fudge);
}
}
@@ -1028,7 +1000,7 @@ void OpaqueNonClientView::LayoutTitleBar() {
int title_left = icon_right + spacing;
title_bounds_.SetRect(title_left, kTitleTopOffset + top_offset,
std::max(0, static_cast<int>(title_right - icon_right)),
- resources()->GetTitleFont().height());
+ title_font_.height());
}
}
@@ -1050,7 +1022,20 @@ void OpaqueNonClientView::InitClass() {
if (!image->isNull())
distributor_logo_ = *image;
+ app_top_left_ = *rb.GetBitmapNamed(IDR_APP_TOP_LEFT);
+ app_top_center_ = *rb.GetBitmapNamed(IDR_APP_TOP_CENTER);
+ app_top_right_ = *rb.GetBitmapNamed(IDR_APP_TOP_RIGHT);
+
initialized = true;
}
}
+// static
+void OpaqueNonClientView::InitAppWindowResources() {
+ static bool initialized = false;
+ if (!initialized) {
+ title_font_ = ResourceBundle::GetSharedInstance().GetFont(
+ ResourceBundle::BaseFont).DeriveFont(1, ChromeFont::BOLD);
+ initialized = true;
+ }
+}
diff --git a/chrome/browser/views/frame/opaque_non_client_view.h b/chrome/browser/views/frame/opaque_non_client_view.h
index 42f9506..5afae53a 100644
--- a/chrome/browser/views/frame/opaque_non_client_view.h
+++ b/chrome/browser/views/frame/opaque_non_client_view.h
@@ -132,11 +132,16 @@ class OpaqueNonClientView : public ChromeViews::NonClientView,
std::wstring accessible_name_;
static void InitClass();
+ static void InitAppWindowResources();
static SkBitmap distributor_logo_;
+ static SkBitmap app_top_left_;
+ static SkBitmap app_top_center_;
+ static SkBitmap app_top_right_;
static WindowResources* active_resources_;
static WindowResources* inactive_resources_;
static WindowResources* active_otr_resources_;
static WindowResources* inactive_otr_resources_;
+ static ChromeFont title_font_;
DISALLOW_EVIL_CONSTRUCTORS(OpaqueNonClientView);
};
diff --git a/chrome/browser/views/window_resources.cc b/chrome/browser/views/window_resources.cc
deleted file mode 100644
index 42b1bc4..0000000
--- a/chrome/browser/views/window_resources.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2006-2008 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 "chrome/browser/views/window_resources.h"
-
-#include "chrome/app/theme/theme_resources.h"
-#include "chrome/common/resource_bundle.h"
-
-#include "SkBitmap.h"
-
-// static
-SkBitmap WindowResources::app_top_left_;
-SkBitmap WindowResources::app_top_center_;
-SkBitmap WindowResources::app_top_right_;
-
-// static
-void WindowResources::InitClass() {
- static bool initialized = false;
- if (!initialized) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- app_top_left_ = *rb.GetBitmapNamed(IDR_APP_TOP_LEFT);
- app_top_center_ = *rb.GetBitmapNamed(IDR_APP_TOP_CENTER);
- app_top_right_ = *rb.GetBitmapNamed(IDR_APP_TOP_RIGHT);
- initialized = true;
- }
-}
diff --git a/chrome/browser/views/window_resources.h b/chrome/browser/views/window_resources.h
index eeea313..30ffe65 100644
--- a/chrome/browser/views/window_resources.h
+++ b/chrome/browser/views/window_resources.h
@@ -7,29 +7,22 @@
#include "SkBitmap.h"
-class ChromeFont;
+// TODO(beng): (http://crbug.com/2395) Move this file to chrome/views.
typedef int FramePartBitmap;
+///////////////////////////////////////////////////////////////////////////////
+// WindowResources
+//
+// An interface implemented by an object providing bitmaps to render the
+// contents of a window frame. The Window may swap in different
+// implementations of this interface to render different modes. The definition
+// of FramePartBitmap depends on the implementation.
+//
class WindowResources {
public:
virtual ~WindowResources() { }
virtual SkBitmap* GetPartBitmap(FramePartBitmap part) const = 0;
- virtual const ChromeFont& GetTitleFont() const = 0;
- virtual SkColor GetTitleColor() const { return SK_ColorWHITE; }
-
- SkBitmap app_top_left() const { return app_top_left_; }
- SkBitmap app_top_center() const { return app_top_center_; }
- SkBitmap app_top_right() const { return app_top_right_; }
-
- protected:
- static void InitClass();
-
- private:
- // Bitmaps shared between all frame types.
- static SkBitmap app_top_left_;
- static SkBitmap app_top_center_;
- static SkBitmap app_top_right_;
};
#endif // CHROME_BROWSER_VIEWS_WINDOW_RESOURCES_H_