summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/gfx/canvas_linux.cc89
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc112
-rw-r--r--chrome/browser/gtk/browser_window_gtk.h2
-rw-r--r--chrome/browser/views/panel_controller.cc79
-rw-r--r--chrome/browser/views/panel_controller.h3
5 files changed, 161 insertions, 124 deletions
diff --git a/app/gfx/canvas_linux.cc b/app/gfx/canvas_linux.cc
index c42df59..d1d391b 100644
--- a/app/gfx/canvas_linux.cc
+++ b/app/gfx/canvas_linux.cc
@@ -124,42 +124,62 @@ Canvas::Canvas() : skia::PlatformCanvas() {
Canvas::~Canvas() {
}
-// static
-void Canvas::SizeStringInt(const std::wstring& text,
- const gfx::Font& font,
- int* width, int* height, int flags) {
- cairo_surface_t* surface =
- cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
- cairo_t* cr = cairo_create(surface);
- PangoLayout* layout = pango_cairo_create_layout(cr);
+static void SetupPangoLayout(PangoLayout* layout,
+ const gfx::Font& font,
+ int flags) {
+ if (!cairo_font_options)
+ UpdateCairoFontOptions();
+ // This needs to be done early on; it has no effect when called just before
+ // pango_cairo_show_layout().
+ pango_cairo_context_set_font_options(
+ pango_layout_get_context(layout), cairo_font_options);
- if (flags & NO_ELLIPSIS) {
+ // Callers of DrawStringInt handle RTL layout themselves, so tell pango to not
+ // scope out RTL characters.
+ pango_layout_set_auto_dir(layout, FALSE);
+
+ if (flags & Canvas::NO_ELLIPSIS) {
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
} else {
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
}
- if (flags & TEXT_ALIGN_CENTER) {
+ if (flags & Canvas::TEXT_ALIGN_CENTER) {
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
- } else if (flags & TEXT_ALIGN_RIGHT) {
+ } else if (flags & Canvas::TEXT_ALIGN_RIGHT) {
pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
}
- if (flags & MULTI_LINE) {
+ if (flags & Canvas::MULTI_LINE) {
pango_layout_set_wrap(layout,
- (flags & CHARACTER_BREAK) ? PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD);
+ (flags & Canvas::CHARACTER_BREAK) ?
+ PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD);
}
- std::string utf8 = WideToUTF8(text);
- pango_layout_set_text(layout, utf8.data(), utf8.size());
PangoFontDescription* desc = PangoFontFromGfxFont(font);
pango_layout_set_font_description(layout, desc);
+ pango_font_description_free(desc);
+}
+
+// static
+void Canvas::SizeStringInt(const std::wstring& text,
+ const gfx::Font& font,
+ int* width, int* height, int flags) {
+ cairo_surface_t* surface =
+ cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
+ cairo_t* cr = cairo_create(surface);
+ PangoLayout* layout = pango_cairo_create_layout(cr);
+
+ SetupPangoLayout(layout, font, flags);
+
+ std::string utf8 = WideToUTF8(text);
+ pango_layout_set_text(layout, utf8.data(), utf8.size());
pango_layout_get_size(layout, width, height);
*width /= PANGO_SCALE;
*height /= PANGO_SCALE;
+
g_object_unref(layout);
- pango_font_description_free(desc);
cairo_destroy(cr);
cairo_surface_destroy(surface);
}
@@ -171,50 +191,19 @@ void Canvas::DrawStringInt(const std::wstring& text,
cairo_t* cr = beginPlatformPaint();
PangoLayout* layout = pango_cairo_create_layout(cr);
- if (!cairo_font_options)
- UpdateCairoFontOptions();
- // This needs to be done early on; it has no effect when called just before
- // pango_cairo_show_layout().
- pango_cairo_context_set_font_options(
- pango_layout_get_context(layout), cairo_font_options);
+ SetupPangoLayout(layout, font, flags);
- // Callers of DrawStringInt handle RTL layout themselves, so tell pango to not
- // scope out RTL characters.
- pango_layout_set_auto_dir(layout, FALSE);
+ pango_layout_set_width(layout, w * PANGO_SCALE);
+ pango_layout_set_height(layout, h * PANGO_SCALE);
cairo_set_source_rgb(cr,
SkColorGetR(color) / 255.0,
SkColorGetG(color) / 255.0,
SkColorGetB(color) / 255.0);
- // TODO(deanm): Implement the rest of the Canvas flags.
- if (!(flags & Canvas::NO_ELLIPSIS))
- pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
-
- pango_layout_set_width(layout, w * PANGO_SCALE);
- pango_layout_set_height(layout, h * PANGO_SCALE);
-
- if (flags & TEXT_ALIGN_CENTER) {
- pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
- } else if (flags & TEXT_ALIGN_RIGHT) {
- pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
- }
-
- if (flags & MULTI_LINE) {
- pango_layout_set_wrap(layout,
- (flags & CHARACTER_BREAK) ? PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD);
- }
-
- if (flags & NO_ELLIPSIS)
- pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
-
std::string utf8 = WideToUTF8(text);
pango_layout_set_text(layout, utf8.data(), utf8.size());
- PangoFontDescription* desc = PangoFontFromGfxFont(font);
- pango_layout_set_font_description(layout, desc);
- pango_font_description_free(desc);
-
int width, height;
pango_layout_get_size(layout, &width, &height);
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 294f635..aa74070 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -1361,21 +1361,26 @@ void BrowserWindowGtk::InitWidgets() {
titlebar_.reset(new BrowserTitlebar(this, window_));
#if defined(OS_CHROMEOS) && defined(COMPACT_NAV_BAR)
- // Make a box that we'll later insert the compact navigation bar into. The
- // tabstrip must go into an hbox with our box so that they can get arranged
- // horizontally.
- GtkWidget* titlebar_hbox = gtk_hbox_new(FALSE, 0);
- GtkWidget* navbar_hbox = gtk_hbox_new(FALSE, 0);
- GtkWidget* status_hbox = gtk_hbox_new(FALSE, 0);
- gtk_widget_show(navbar_hbox);
- gtk_widget_show(titlebar_hbox);
- gtk_widget_show(status_hbox);
- gtk_box_pack_start(GTK_BOX(titlebar_hbox), navbar_hbox, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(titlebar_hbox), titlebar_->widget(), TRUE, TRUE,
- 0);
- gtk_box_pack_start(GTK_BOX(titlebar_hbox), status_hbox, FALSE, FALSE, 0);
-
- gtk_box_pack_start(GTK_BOX(window_vbox), titlebar_hbox, FALSE, FALSE, 0);
+ GtkWidget* titlebar_hbox = NULL;
+ GtkWidget* navbar_hbox = NULL;
+ GtkWidget* status_hbox = NULL;
+ if (browser_->type() == Browser::TYPE_NORMAL) {
+ // Make a box that we'll later insert the compact navigation bar into. The
+ // tabstrip must go into an hbox with our box so that they can get arranged
+ // horizontally.
+ titlebar_hbox = gtk_hbox_new(FALSE, 0);
+ navbar_hbox = gtk_hbox_new(FALSE, 0);
+ status_hbox = gtk_hbox_new(FALSE, 0);
+ gtk_widget_show(navbar_hbox);
+ gtk_widget_show(titlebar_hbox);
+ gtk_widget_show(status_hbox);
+ gtk_box_pack_start(GTK_BOX(titlebar_hbox), navbar_hbox, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(titlebar_hbox), titlebar_->widget(), TRUE, TRUE,
+ 0);
+ gtk_box_pack_start(GTK_BOX(titlebar_hbox), status_hbox, FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(window_vbox), titlebar_hbox, FALSE, FALSE, 0);
+ }
#else
// Insert the tabstrip into the window.
@@ -1391,7 +1396,9 @@ void BrowserWindowGtk::InitWidgets() {
toolbar_->Init(browser_->profile(), window_);
toolbar_->AddToolbarToBox(content_vbox_);
#if defined(OS_CHROMEOS) && defined(COMPACT_NAV_BAR)
- gtk_widget_hide(toolbar_->widget());
+ if (browser_->type() == Browser::TYPE_NORMAL) {
+ gtk_widget_hide(toolbar_->widget());
+ }
#endif
bookmark_bar_.reset(new BookmarkBarGtk(browser_->profile(), browser_.get(),
@@ -1465,41 +1472,44 @@ void BrowserWindowGtk::InitWidgets() {
browser_->tabstrip_model()->AddObserver(this);
#if defined(OS_CHROMEOS) && defined(COMPACT_NAV_BAR)
- // Create the compact navigation bar. This must be done after adding
- // everything to the window since it's done in Views, which expects to call
- // realize (requiring a window) in the Init function.
- views::WidgetGtk* clb_widget =
- new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
- clb_widget->set_delete_on_destroy(true);
- // Must initialize with a NULL parent since the widget will assume the parent
- // is also a WidgetGtk. Then we can parent the native widget afterwards.
- clb_widget->Init(NULL, gfx::Rect(0, 0, 100, 30));
- gtk_widget_reparent(clb_widget->GetNativeView(), navbar_hbox);
-
- compact_navigation_bar_ = new CompactNavigationBar(browser_.get());
-
- clb_widget->SetContentsView(compact_navigation_bar_);
- compact_navigation_bar_->Init();
-
- // Create the status area.
- views::WidgetGtk* status_widget =
- new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
- status_widget->set_delete_on_destroy(true);
- status_widget->Init(NULL, gfx::Rect(0, 0, 100, 30));
- gtk_widget_reparent(status_widget->GetNativeView(), status_hbox);
- status_area_ = new StatusAreaView(browser());
- status_widget->SetContentsView(status_area_);
- status_area_->Init();
-
- // Must be after Init.
- gtk_widget_set_size_request(clb_widget->GetNativeView(),
- compact_navigation_bar_->GetPreferredSize().width(), 20);
- gfx::Size status_area_size = status_area_->GetPreferredSize();
- gtk_widget_set_size_request(status_widget->GetNativeView(),
- status_area_size.width(),
- status_area_size.height());
- clb_widget->Show();
- status_widget->Show();
+ if (browser_->type() == Browser::TYPE_NORMAL) {
+ // Create the compact navigation bar. This must be done after adding
+ // everything to the window since it's done in Views, which expects to call
+ // realize (requiring a window) in the Init function.
+ views::WidgetGtk* clb_widget =
+ new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
+ clb_widget->set_delete_on_destroy(true);
+ // Must initialize with a NULL parent since the widget will assume the
+ // parent is also a WidgetGtk. Then we can parent the native widget
+ // afterwards.
+ clb_widget->Init(NULL, gfx::Rect(0, 0, 100, 30));
+ gtk_widget_reparent(clb_widget->GetNativeView(), navbar_hbox);
+
+ compact_navigation_bar_ = new CompactNavigationBar(browser_.get());
+
+ clb_widget->SetContentsView(compact_navigation_bar_);
+ compact_navigation_bar_->Init();
+
+ // Create the status area.
+ views::WidgetGtk* status_widget =
+ new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
+ status_widget->set_delete_on_destroy(true);
+ status_widget->Init(NULL, gfx::Rect(0, 0, 100, 30));
+ gtk_widget_reparent(status_widget->GetNativeView(), status_hbox);
+ status_area_ = new StatusAreaView(browser());
+ status_widget->SetContentsView(status_area_);
+ status_area_->Init();
+
+ // Must be after Init.
+ gtk_widget_set_size_request(clb_widget->GetNativeView(),
+ compact_navigation_bar_->GetPreferredSize().width(), 20);
+ gfx::Size status_area_size = status_area_->GetPreferredSize();
+ gtk_widget_set_size_request(status_widget->GetNativeView(),
+ status_area_size.width(),
+ status_area_size.height());
+ clb_widget->Show();
+ status_widget->Show();
+ }
#endif // OS_CHROMEOS
}
diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h
index 92d3733..7af9c11 100644
--- a/chrome/browser/gtk/browser_window_gtk.h
+++ b/chrome/browser/gtk/browser_window_gtk.h
@@ -169,6 +169,8 @@ class BrowserWindowGtk : public BrowserWindow,
GtkWindow* window() const { return window_; }
+ gfx::Rect bounds() const { return bounds_; }
+
static void RegisterUserPrefs(PrefService* prefs);
protected:
diff --git a/chrome/browser/views/panel_controller.cc b/chrome/browser/views/panel_controller.cc
index 620494c..a6623e4 100644
--- a/chrome/browser/views/panel_controller.cc
+++ b/chrome/browser/views/panel_controller.cc
@@ -17,6 +17,7 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "views/controls/button/image_button.h"
+#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/event.h"
#include "views/view.h"
@@ -25,19 +26,28 @@
static int close_button_width;
static int close_button_height;
static SkBitmap* close_button_n;
+static SkBitmap* close_button_m;
static SkBitmap* close_button_h;
static SkBitmap* close_button_p;
-static gfx::Font* title_font = NULL;
+static gfx::Font* active_font = NULL;
+static gfx::Font* inactive_font = NULL;
namespace {
const int kTitleWidth = 200;
-const int kTitleHeight = 24;
-const int kTitlePad = 8;
-const int kButtonPad = 8;
-const SkColor kTitleBackground = 0xFFDDDDDD;
-const SkColor kActiveText = SK_ColorBLACK;
-const SkColor kInactiveText = 0xFF666666;
+const int kTitleHeight = 20;
+const int kTitleIconSize = 16;
+const int kTitleWidthPad = 2;
+const int kTitleHeightPad = 1;
+const int kButtonPad = 4;
+
+const SkColor kActiveGradientStart = 0xffebeff9;
+const SkColor kActiveGradientEnd = 0xffb3c4f6;
+const SkColor kInactiveGradientStart = 0xfff2f2f2;
+const SkColor kInactiveGradientEnd = 0xfff2f2f2;
+const SkColor kActiveColor = SK_ColorBLACK;
+const SkColor kInactiveColor = 0xff333333;
+const SkColor kCloseButtonColor = SK_ColorBLACK;
static bool resources_initialized;
static void InitializeResources() {
@@ -47,8 +57,10 @@ static void InitializeResources() {
resources_initialized = true;
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- title_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont));
+ inactive_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont));
+ active_font = new gfx::Font(inactive_font->DeriveFont(0, gfx::Font::BOLD));
close_button_n = rb.GetBitmapNamed(IDR_TAB_CLOSE);
+ close_button_m = rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK);
close_button_h = rb.GetBitmapNamed(IDR_TAB_CLOSE_H);
close_button_p = rb.GetBitmapNamed(IDR_TAB_CLOSE_P);
close_button_width = close_button_n->width();
@@ -66,7 +78,7 @@ PanelController::PanelController(BrowserWindowGtk* browser_window)
dragging_(false) {
title_window_ = new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW);
gfx::Rect title_bounds(
- 0, 0, browser_window->GetRestoredBounds().width(), kTitleHeight);
+ 0, 0, browser_window->bounds().width(), kTitleHeight);
title_window_->Init(NULL, title_bounds);
title_ = title_window_->GetNativeView();
title_xid_ = x11_util::GetX11WindowFromGtkWidget(title_);
@@ -93,8 +105,10 @@ PanelController::PanelController(BrowserWindowGtk* browser_window)
}
void PanelController::UpdateTitleBar() {
- title_content_->title_label()->SetText(UTF16ToWideHack(
- browser_window_->browser()->GetWindowTitleForCurrentTab()));
+ Browser* browser = browser_window_->browser();
+ title_content_->title_label()->SetText(
+ UTF16ToWideHack(browser->GetWindowTitleForCurrentTab()));
+ title_content_->title_icon()->SetImage(browser->GetCurrentPageIcon());
}
bool PanelController::TitleMousePressed(const views::MouseEvent& event) {
@@ -205,27 +219,38 @@ PanelController::TitleContentView::TitleContentView(
close_button_->SetImage(views::CustomButton::BS_NORMAL, close_button_n);
close_button_->SetImage(views::CustomButton::BS_HOT, close_button_h);
close_button_->SetImage(views::CustomButton::BS_PUSHED, close_button_p);
+ close_button_->SetBackground(
+ kCloseButtonColor, close_button_n, close_button_m);
AddChildView(close_button_);
- title_label_ = new views::Label(std::wstring(), *title_font);
+ title_icon_ = new views::ImageView();
+ AddChildView(title_icon_);
+ title_label_ = new views::Label(std::wstring());
title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- title_label_->SetColor(kInactiveText);
AddChildView(title_label_);
- set_background(views::Background::CreateSolidBackground(0xdd, 0xdd, 0xdd, 1));
+ // Default to inactive
+ OnFocusOut();
}
void PanelController::TitleContentView::Layout() {
+ int close_button_x = bounds().width() - (close_button_width + kButtonPad);
close_button_->SetBounds(
- bounds().width() - (close_button_width + kButtonPad),
+ close_button_x,
(bounds().height() - close_button_height) / 2,
close_button_width,
close_button_height);
+ title_icon_->SetBounds(
+ kTitleWidthPad,
+ kTitleHeightPad * 2,
+ kTitleIconSize,
+ kTitleIconSize);
+ int title_x = kTitleWidthPad * 2 + kTitleIconSize;
title_label_->SetBounds(
- kTitlePad,
- 0,
- bounds().width() - (kTitlePad + close_button_width + 2 * kButtonPad),
- bounds().height());
+ title_x,
+ kTitleHeightPad,
+ close_button_x - (title_x + kButtonPad),
+ bounds().height() - kTitleHeightPad);
}
bool PanelController::TitleContentView::OnMousePressed(
@@ -244,12 +269,20 @@ bool PanelController::TitleContentView::OnMouseDragged(
}
void PanelController::TitleContentView::OnFocusIn() {
- title_label_->SetColor(kActiveText);
- title_label_->SchedulePaint();
+ set_background(views::Background::CreateVerticalGradientBackground(
+ kActiveGradientStart, kActiveGradientEnd));
+ title_label_->SetColor(kActiveColor);
+ title_label_->SetFont(*active_font);
+ Layout();
+ SchedulePaint();
}
void PanelController::TitleContentView::OnFocusOut() {
- title_label_->SetColor(kInactiveText);
- title_label_->SchedulePaint();
+ set_background(views::Background::CreateVerticalGradientBackground(
+ kInactiveGradientStart, kInactiveGradientEnd));
+ title_label_->SetColor(kInactiveColor);
+ title_label_->SetFont(*inactive_font);
+ Layout();
+ SchedulePaint();
}
diff --git a/chrome/browser/views/panel_controller.h b/chrome/browser/views/panel_controller.h
index 0379e7b..de7d613 100644
--- a/chrome/browser/views/panel_controller.h
+++ b/chrome/browser/views/panel_controller.h
@@ -14,6 +14,7 @@ typedef unsigned long XID;
namespace views {
class ImageButton;
+class ImageView;
class Label;
class MouseEvent;
class WidgetGtk;
@@ -49,10 +50,12 @@ class PanelController : public views::ButtonListener {
void OnFocusIn();
void OnFocusOut();
+ views::ImageView* title_icon() { return title_icon_; }
views::Label* title_label() { return title_label_; }
views::ImageButton* close_button() { return close_button_; }
private:
+ views::ImageView* title_icon_;
views::Label* title_label_;
views::ImageButton* close_button_;
PanelController* panel_controller_;