summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-30 22:45:45 +0000
committergspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-30 22:45:45 +0000
commitc766a168bb731fc8618b0a202935c75fe67494ee (patch)
tree08687e47fef17d785a3e5f9df1478973a80edee9
parent971b3c5679671ae9f08190a54d7cd0ed30ec9cfb (diff)
downloadchromium_src-c766a168bb731fc8618b0a202935c75fe67494ee.zip
chromium_src-c766a168bb731fc8618b0a202935c75fe67494ee.tar.gz
chromium_src-c766a168bb731fc8618b0a202935c75fe67494ee.tar.bz2
Adding support for ChromeOS snapshot window titles and favicons.
TEST=build and ran with chromeos-wm BUG=chromium-os:2866, chromium-os:2867 Review URL: http://codereview.chromium.org/2857005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51305 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drop_shadow_label.cc79
-rw-r--r--chrome/browser/chromeos/drop_shadow_label.h55
-rw-r--r--chrome/browser/chromeos/wm_overview_controller.cc79
-rw-r--r--chrome/browser/chromeos/wm_overview_controller.h1
-rw-r--r--chrome/browser/chromeos/wm_overview_fav_icon.cc83
-rw-r--r--chrome/browser/chromeos/wm_overview_fav_icon.h43
-rw-r--r--chrome/browser/chromeos/wm_overview_snapshot.cc3
-rw-r--r--chrome/browser/chromeos/wm_overview_snapshot.h4
-rw-r--r--chrome/browser/chromeos/wm_overview_title.cc115
-rw-r--r--chrome/browser/chromeos/wm_overview_title.h45
-rw-r--r--chrome/chrome_browser.gypi5
-rw-r--r--views/controls/label.cc133
-rw-r--r--views/controls/label.h28
13 files changed, 577 insertions, 96 deletions
diff --git a/chrome/browser/chromeos/drop_shadow_label.cc b/chrome/browser/chromeos/drop_shadow_label.cc
new file mode 100644
index 0000000..5c5fa30
--- /dev/null
+++ b/chrome/browser/chromeos/drop_shadow_label.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2010 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/chromeos/drop_shadow_label.h"
+
+#include "gfx/canvas.h"
+#include "gfx/color_utils.h"
+
+using views::Label;
+
+namespace chromeos {
+
+static const int kDefaultDropShadowSize = 2;
+
+// Default color is black.
+static const SkColor kDefaultColor = 0x000000;
+
+static const float kShadowOpacity = 0.2;
+
+DropShadowLabel::DropShadowLabel() : Label() {
+ Init();
+}
+
+void DropShadowLabel::Init() {
+ drop_shadow_size_ = kDefaultDropShadowSize;
+}
+
+void DropShadowLabel::SetDropShadowSize(int drop_shadow_size) {
+ if (drop_shadow_size != drop_shadow_size_) {
+ drop_shadow_size_ = drop_shadow_size;
+ invalidate_text_size();
+ SchedulePaint();
+ }
+}
+
+void DropShadowLabel::PaintText(gfx::Canvas* canvas,
+ const std::wstring& text,
+ const gfx::Rect& text_bounds,
+ int flags) {
+ if (drop_shadow_size_ > 0) {
+ SkColor color = SkColorSetARGB(kShadowOpacity * SkColorGetA(GetColor()),
+ SkColorGetR(kDefaultColor),
+ SkColorGetG(kDefaultColor),
+ SkColorGetB(kDefaultColor));
+ for (int i = 0; i < drop_shadow_size_; i++) {
+ canvas->DrawStringInt(text, font(), color,
+ text_bounds.x() + i, text_bounds.y(),
+ text_bounds.width(), text_bounds.height(), flags);
+ canvas->DrawStringInt(text, font(), color,
+ text_bounds.x() + i, text_bounds.y() + i,
+ text_bounds.width(), text_bounds.height(), flags);
+ canvas->DrawStringInt(text, font(), color,
+ text_bounds.x(), text_bounds.y() + i,
+ text_bounds.width(), text_bounds.height(), flags);
+ }
+ }
+
+ canvas->DrawStringInt(text, font(), GetColor(),
+ text_bounds.x(), text_bounds.y(),
+ text_bounds.width(), text_bounds.height(), flags);
+
+ if (HasFocus() || paint_as_focused()) {
+ gfx::Rect focus_bounds = text_bounds;
+ focus_bounds.Inset(-Label::kFocusBorderPadding,
+ -Label::kFocusBorderPadding);
+ canvas->DrawFocusRect(focus_bounds.x(), focus_bounds.y(),
+ focus_bounds.width(), focus_bounds.height());
+ }
+}
+
+gfx::Size DropShadowLabel::GetTextSize() const {
+ gfx::Size text_size = Label::GetTextSize();
+ text_size.SetSize(text_size.width() + drop_shadow_size_,
+ text_size.height() + drop_shadow_size_);
+ return text_size;
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/drop_shadow_label.h b/chrome/browser/chromeos/drop_shadow_label.h
new file mode 100644
index 0000000..21ed7eb
--- /dev/null
+++ b/chrome/browser/chromeos/drop_shadow_label.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2010 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 CHROME_BROWSER_CHROMEOS_DROP_SHADOW_LABEL_H_
+#define CHROME_BROWSER_CHROMEOS_DROP_SHADOW_LABEL_H_
+
+#include "gfx/font.h"
+#include "views/controls/label.h"
+
+namespace chromeos {
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DropShadowLabel class
+//
+// A drop shadow label is a view subclass that can display a string
+// with a drop shadow.
+//
+/////////////////////////////////////////////////////////////////////////////
+class DropShadowLabel : public views::Label {
+ public:
+ DropShadowLabel();
+
+ // Sets the size of the drop shadow drawn under the text.
+ // Defaults to two. Note that this is a really simplistic drop
+ // shadow -- it gets more expensive to draw the larger it gets,
+ // since it simply draws more copies of the string. For instance,
+ // for a value of two, the string is draw seven times. In general,
+ // it is drawn three extra times for each increment of |size|.
+ void SetDropShadowSize(int size);
+
+ // Return the size of the drop shadow in pixels.
+ int drop_shadow_size() const { return drop_shadow_size_; }
+
+ // Overridden to paint the text differently from the base class.
+ virtual void PaintText(gfx::Canvas* canvas,
+ const std::wstring& text,
+ const gfx::Rect& text_bounds,
+ int flags);
+
+ protected:
+ virtual gfx::Size GetTextSize() const;
+
+ private:
+ void Init();
+
+ int drop_shadow_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(DropShadowLabel);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DROP_SHADOW_LABEL_H_
diff --git a/chrome/browser/chromeos/wm_overview_controller.cc b/chrome/browser/chromeos/wm_overview_controller.cc
index 87ee4c0..db364be 100644
--- a/chrome/browser/chromeos/wm_overview_controller.cc
+++ b/chrome/browser/chromeos/wm_overview_controller.cc
@@ -11,7 +11,9 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/wm_ipc.h"
+#include "chrome/browser/chromeos/wm_overview_fav_icon.h"
#include "chrome/browser/chromeos/wm_overview_snapshot.h"
+#include "chrome/browser/chromeos/wm_overview_title.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
@@ -57,6 +59,12 @@ static const double kSnapshotWebPageRatio =
// that a snapshot can take up.
static const double kSnapshotMaxSizeRatio = 0.77;
+// This is the height of the title in pixels.
+static const int kTitleHeight = 32;
+
+// The number of additional padding pixels to remove from the title width.
+static const int kFavIconPadding = 5;
+
class BrowserListener : public TabStripModelObserver {
public:
BrowserListener(Browser* browser, WmOverviewController* parent);
@@ -145,8 +153,16 @@ class BrowserListener : public TabStripModelObserver {
Browser* browser_; // Not owned
WmOverviewController* controller_; // Not owned
- // Widgets containing snapshot images for this browser.
- typedef std::vector<WmOverviewSnapshot* > SnapshotVector;
+ // Widgets containing snapshot images for this browser. Note that
+ // these are all subclasses of WidgetGtk, and they are all added to
+ // parents, so they will be deleted by the parents when they are
+ // closed.
+ struct SnapshotNode {
+ WmOverviewSnapshot* snapshot; // Not owned
+ WmOverviewTitle* title; // Not owned
+ WmOverviewFavIcon* fav_icon; // Not owned
+ };
+ typedef std::vector<SnapshotNode> SnapshotVector;
SnapshotVector snapshots_;
// True if the snapshots are showing.
@@ -205,9 +221,9 @@ void BrowserListener::TabMoved(TabContents* contents,
// Need to reorder tab in the snapshots list, and reset the window
// type atom on the affected snapshots (the one moved, and all the
// ones after it), so that their indices are correct.
- WmOverviewSnapshot* snapshot = snapshots_[from_index];
+ SnapshotNode node = snapshots_[from_index];
snapshots_.erase(snapshots_.begin() + from_index);
- snapshots_.insert(snapshots_.begin() + to_index, snapshot);
+ snapshots_.insert(snapshots_.begin() + to_index, node);
RenumberSnapshots(std::min(to_index, from_index));
UpdateSelectedIndex(browser_->selected_index());
@@ -217,9 +233,12 @@ void BrowserListener::TabChangedAt(
TabContents* contents,
int index,
TabStripModelObserver::TabChangeType change_type) {
- if (change_type != TabStripModelObserver::LOADING_ONLY &&
- change_type != TabStripModelObserver::TITLE_NOT_LOADING) {
- ReloadSnapshot(index);
+ if (change_type != TabStripModelObserver::LOADING_ONLY) {
+ snapshots_[index].title->SetTitle(contents->GetTitle());
+ snapshots_[index].title->SetUrl(contents->GetURL());
+ snapshots_[index].fav_icon->SetFavIcon(contents->GetFavIcon());
+ if (change_type != TabStripModelObserver::TITLE_NOT_LOADING)
+ ReloadSnapshot(index);
}
}
@@ -235,16 +254,15 @@ void BrowserListener::TabSelectedAt(TabContents* old_contents,
}
void BrowserListener::ReloadSnapshot(int index) {
- snapshots_[index]->reload_snapshot();
+ snapshots_[index].snapshot->reload_snapshot();
controller_->StartDelayTimer();
}
void BrowserListener::RecreateSnapshots() {
snapshots_.clear();
- for (int i = 0; i < count(); ++i) {
+ for (int i = 0; i < count(); ++i)
InsertSnapshot(i);
- }
RenumberSnapshots(0);
}
@@ -268,7 +286,7 @@ void BrowserListener::UpdateSelectedIndex(int index) {
bool BrowserListener::ConfigureNextUnconfiguredSnapshot() {
for (SnapshotVector::size_type i = 0; i < snapshots_.size(); ++i) {
- WmOverviewSnapshot* cell = snapshots_[i];
+ WmOverviewSnapshot* cell = snapshots_[i].snapshot;
if (!cell->configured_snapshot()) {
ConfigureCell(cell, i);
return true;
@@ -286,9 +304,13 @@ void BrowserListener::RestoreOriginalSelectedTab() {
void BrowserListener::ShowSnapshots() {
for (SnapshotVector::size_type i = 0; i < snapshots_.size(); ++i) {
- WmOverviewSnapshot* snapshot = snapshots_[i];
- if (!snapshot->IsVisible())
- snapshot->Show();
+ const SnapshotNode& node = snapshots_[i];
+ if (!node.snapshot->IsVisible())
+ node.snapshot->Show();
+ if (!snapshots_[i].title->IsVisible())
+ node.title->Show();
+ if (!snapshots_[i].fav_icon->IsVisible())
+ node.fav_icon->Show();
}
}
@@ -362,23 +384,38 @@ void BrowserListener::ConfigureCell(WmOverviewSnapshot* cell,
}
void BrowserListener::InsertSnapshot(int index) {
- WmOverviewSnapshot* snapshot = new WmOverviewSnapshot;
- snapshot->Init(CalculateCellSize(), browser_, index);
- snapshots_.insert(snapshots_.begin() + index, snapshot);
- snapshot->reload_snapshot();
+ SnapshotNode node;
+ node.snapshot = new WmOverviewSnapshot;
+ gfx::Size cell_size = CalculateCellSize();
+ node.snapshot->Init(cell_size, browser_, index);
+
+ node.fav_icon = new WmOverviewFavIcon;
+ node.fav_icon->Init(node.snapshot);
+ node.fav_icon->SetFavIcon(browser_->GetTabContentsAt(index)->GetFavIcon());
+
+ node.title = new WmOverviewTitle;
+ node.title->Init(gfx::Size(cell_size.width() -
+ WmOverviewFavIcon::kIconSize - kFavIconPadding,
+ kTitleHeight), node.snapshot);
+ node.title->SetTitle(browser_->GetTabContentsAt(index)->GetTitle());
+
+ snapshots_.insert(snapshots_.begin() + index, node);
+ node.snapshot->reload_snapshot();
controller_->StartDelayTimer();
}
// Removes the snapshot at index.
void BrowserListener::ClearSnapshot(int index) {
- snapshots_[index]->CloseNow();
+ snapshots_[index].snapshot->CloseNow();
+ snapshots_[index].title->CloseNow();
+ snapshots_[index].fav_icon->CloseNow();
snapshots_.erase(snapshots_.begin() + index);
}
void BrowserListener::RenumberSnapshots(int start_index) {
for (SnapshotVector::size_type i = start_index; i < snapshots_.size(); ++i) {
- if (snapshots_[i]->index() != static_cast<int>(i))
- snapshots_[i]->UpdateIndex(browser_, i);
+ if (snapshots_[i].snapshot->index() != static_cast<int>(i))
+ snapshots_[i].snapshot->UpdateIndex(browser_, i);
}
}
diff --git a/chrome/browser/chromeos/wm_overview_controller.h b/chrome/browser/chromeos/wm_overview_controller.h
index 32d7538..19a4ed0 100644
--- a/chrome/browser/chromeos/wm_overview_controller.h
+++ b/chrome/browser/chromeos/wm_overview_controller.h
@@ -26,7 +26,6 @@ class RenderWidgetHost;
namespace chromeos {
class BrowserListener;
-class WmOverviewSnapshot;
// WmOverviewController is responsible for managing a list of objects
// that listen to the browsers (BrowserListeners, defined in the
diff --git a/chrome/browser/chromeos/wm_overview_fav_icon.cc b/chrome/browser/chromeos/wm_overview_fav_icon.cc
new file mode 100644
index 0000000..ad9dfa8
--- /dev/null
+++ b/chrome/browser/chromeos/wm_overview_fav_icon.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2010 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/chromeos/wm_overview_fav_icon.h"
+
+#include <vector>
+
+#include "app/x11_util.h"
+#include "chrome/browser/chromeos/wm_ipc.h"
+#include "chrome/browser/chromeos/wm_overview_snapshot.h"
+#include "skia/ext/image_operations.h"
+#include "third_party/cros/chromeos_wm_ipc_enums.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "views/controls/image_view.h"
+#include "views/controls/label.h"
+#include "views/grid_layout.h"
+
+using std::vector;
+
+#if !defined(OS_CHROMEOS)
+#error This file is only meant to be compiled for ChromeOS
+#endif
+
+namespace chromeos {
+
+const int WmOverviewFavIcon::kIconSize = 32;
+
+WmOverviewFavIcon::WmOverviewFavIcon()
+ : WidgetGtk(TYPE_WINDOW),
+ fav_icon_view_(NULL) {
+}
+
+void WmOverviewFavIcon::Init(WmOverviewSnapshot* snapshot) {
+ MakeTransparent();
+
+ fav_icon_view_ = new views::ImageView();
+
+ WidgetGtk::Init(NULL, gfx::Rect(0, 0, 0, 0));
+
+ SetContentsView(fav_icon_view_);
+
+ // Set the window type
+ vector<int> params;
+ params.push_back(x11_util::GetX11WindowFromGtkWidget(
+ GTK_WIDGET(snapshot->GetNativeView())));
+ WmIpc::instance()->SetWindowType(
+ GetNativeView(),
+ WM_IPC_WINDOW_CHROME_TAB_FAV_ICON,
+ &params);
+}
+
+
+void WmOverviewFavIcon::SetFavIcon(const SkBitmap& image) {
+ CHECK(fav_icon_view_) << "Init not called before setting fav icon.";
+ SkBitmap icon;
+ if (image.width() && image.height()) {
+ float aspect_ratio = static_cast<float>(image.width()) / image.height();
+ int new_width = kIconSize;
+ int new_height = kIconSize;
+ if (aspect_ratio > 1.0f) {
+ new_height = kIconSize / aspect_ratio;
+ } else {
+ new_width = kIconSize * aspect_ratio;
+ }
+ if (new_width && new_height) {
+ icon = skia::ImageOperations::Resize(
+ image, skia::ImageOperations::RESIZE_BOX,
+ new_width, new_height);
+ }
+ }
+
+ fav_icon_view_->SetImage(icon);
+
+ // Reset the bounds to the size of the image.
+ gfx::Rect bounds;
+ GetBounds(&bounds, false);
+ bounds.set_width(icon.width());
+ bounds.set_height(icon.height());
+ SetBounds(bounds);
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/wm_overview_fav_icon.h b/chrome/browser/chromeos/wm_overview_fav_icon.h
new file mode 100644
index 0000000..0d22498
--- /dev/null
+++ b/chrome/browser/chromeos/wm_overview_fav_icon.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2010 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 CHROME_BROWSER_CHROMEOS_WM_OVERVIEW_FAV_ICON_H_
+#define CHROME_BROWSER_CHROMEOS_WM_OVERVIEW_FAV_ICON_H_
+
+#include "views/widget/widget_gtk.h"
+
+class SkBitmap;
+
+namespace views {
+class ImageView;
+}
+
+namespace chromeos {
+
+class WmOverviewSnapshot;
+
+// A single fav icon displayed by WmOverviewController.
+class WmOverviewFavIcon : public views::WidgetGtk {
+ public:
+ static const int kIconSize;
+
+ WmOverviewFavIcon();
+
+ // Initializes the fav icon to 0x0 size.
+ void Init(WmOverviewSnapshot* snapshot);
+
+ // Setting the FavIcon sets the bounds to the size of the given
+ // image.
+ void SetFavIcon(const SkBitmap& image);
+
+ private:
+ // This control is the contents view for this widget.
+ views::ImageView* fav_icon_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(WmOverviewFavIcon);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_WM_OVERVIEW_FAV_ICON_H_
diff --git a/chrome/browser/chromeos/wm_overview_snapshot.cc b/chrome/browser/chromeos/wm_overview_snapshot.cc
index 6ee9cb7..dccf223 100644
--- a/chrome/browser/chromeos/wm_overview_snapshot.cc
+++ b/chrome/browser/chromeos/wm_overview_snapshot.cc
@@ -10,13 +10,10 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/chromeos/wm_ipc.h"
-#include "views/border.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/grid_layout.h"
-using views::ColumnSet;
-using views::GridLayout;
using std::vector;
#if !defined(OS_CHROMEOS)
diff --git a/chrome/browser/chromeos/wm_overview_snapshot.h b/chrome/browser/chromeos/wm_overview_snapshot.h
index 7bc3699..1257866 100644
--- a/chrome/browser/chromeos/wm_overview_snapshot.h
+++ b/chrome/browser/chromeos/wm_overview_snapshot.h
@@ -14,8 +14,8 @@ class Browser;
namespace chromeos {
-// A single snapshot displayed by WmOverviewController.
-// WmOverviewSnapshot contains a label, favicon and snapshot.
+// WmOverviewSnapshot contains a snapshot image of the tab at the
+// given index.
class WmOverviewSnapshot : public views::WidgetGtk {
public:
WmOverviewSnapshot();
diff --git a/chrome/browser/chromeos/wm_overview_title.cc b/chrome/browser/chromeos/wm_overview_title.cc
new file mode 100644
index 0000000..1c4a249
--- /dev/null
+++ b/chrome/browser/chromeos/wm_overview_title.cc
@@ -0,0 +1,115 @@
+// Copyright (c) 2010 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/chromeos/wm_overview_title.h"
+
+#include <vector>
+
+#include "app/x11_util.h"
+#include "base/string16.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chromeos/drop_shadow_label.h"
+#include "chrome/browser/chromeos/wm_ipc.h"
+#include "chrome/browser/chromeos/wm_overview_snapshot.h"
+#include "third_party/cros/chromeos_wm_ipc_enums.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "views/border.h"
+#include "views/grid_layout.h"
+#include "views/view.h"
+
+using std::vector;
+using views::ColumnSet;
+using views::GridLayout;
+using views::View;
+using gfx::Font;
+
+#if !defined(OS_CHROMEOS)
+#error This file is only meant to be compiled for ChromeOS
+#endif
+
+namespace chromeos {
+
+// The padding between the title and the URL, in pixels.
+static const int kVerticalPadding = 2;
+
+// This is the size (in pixels) of the drop shadow on the title and url text.
+static const int kDropShadowSize = 2;
+
+namespace {
+// Finds a font based on the base font that is no taller than the
+// given value (well, unless the font at size 1 is taller than the
+// given value).
+Font FindFontThisHigh(int pixels, Font base) {
+ Font font = Font::CreateFont(base.FontName(), 1);
+ Font last_font = font;
+ while (font.height() < pixels) {
+ last_font = font;
+ font = font.DeriveFont(1, Font::BOLD);
+ }
+ return last_font;
+}
+} // Anonymous namespace
+
+WmOverviewTitle::WmOverviewTitle()
+ : WidgetGtk(TYPE_WINDOW),
+ title_label_(NULL),
+ url_label_(NULL) {
+}
+
+void WmOverviewTitle::Init(const gfx::Size& size,
+ WmOverviewSnapshot* snapshot) {
+ MakeTransparent();
+
+ title_label_ = new DropShadowLabel();
+ title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ title_label_->SetColor(SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF));
+ title_label_->SetDropShadowSize(kDropShadowSize);
+ title_label_->SetFont(FindFontThisHigh(16, title_label_->font()));
+
+ url_label_ = new DropShadowLabel();
+ url_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ url_label_->SetColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF));
+ url_label_->SetDropShadowSize(kDropShadowSize);
+ url_label_->SetFont(FindFontThisHigh(14, title_label_->font()));
+
+ // Create a new view to be the host for the grid.
+ View* view = new View();
+ GridLayout* layout = new GridLayout(view);
+ view->SetLayoutManager(layout);
+
+ int title_cs_id = 0;
+ ColumnSet* columns = layout->AddColumnSet(title_cs_id);
+ columns->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
+ GridLayout::FIXED, size.width(), 0);
+
+ layout->StartRow(0, title_cs_id);
+ layout->AddView(title_label_);
+ layout->StartRowWithPadding(1, title_cs_id, 0, kVerticalPadding);
+ layout->AddView(url_label_);
+
+ // Realize the widget.
+ WidgetGtk::Init(NULL, gfx::Rect(size));
+
+ // Make the view the contents view for this widget.
+ SetContentsView(view);
+
+ // Set the window type
+ vector<int> params;
+ params.push_back(x11_util::GetX11WindowFromGtkWidget(
+ GTK_WIDGET(snapshot->GetNativeView())));
+ WmIpc::instance()->SetWindowType(
+ GetNativeView(),
+ WM_IPC_WINDOW_CHROME_TAB_TITLE,
+ &params);
+}
+
+void WmOverviewTitle::SetTitle(const string16& title) {
+ title_label_->SetText(UTF16ToWide(title));
+}
+
+void WmOverviewTitle::SetUrl(const GURL& url) {
+ url_label_->SetURL(url);
+}
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/wm_overview_title.h b/chrome/browser/chromeos/wm_overview_title.h
new file mode 100644
index 0000000..90e4bd5
--- /dev/null
+++ b/chrome/browser/chromeos/wm_overview_title.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2010 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 CHROME_BROWSER_CHROMEOS_WM_OVERVIEW_TITLE_H_
+#define CHROME_BROWSER_CHROMEOS_WM_OVERVIEW_TITLE_H_
+
+#include "base/string16.h"
+#include "views/widget/widget_gtk.h"
+
+class Browser;
+class GURL;
+
+namespace gfx {
+class Size;
+}
+
+namespace chromeos {
+
+class DropShadowLabel;
+class WmOverviewSnapshot;
+
+// WmOverviewTitle contains the title and URL of an associated tab
+// snapshot.
+class WmOverviewTitle : public views::WidgetGtk {
+ public:
+ WmOverviewTitle();
+ void Init(const gfx::Size& size, WmOverviewSnapshot* snapshot);
+
+ void SetTitle(const string16& title);
+ void SetUrl(const GURL& url);
+
+ private:
+ // This contains the title of the tab contents.
+ DropShadowLabel* title_label_;
+
+ // This contains the url of the tab contents.
+ DropShadowLabel* url_label_;
+
+ DISALLOW_COPY_AND_ASSIGN(WmOverviewTitle);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_WM_OVERVIEW_TITLE_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 4292a17..94e361f 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -383,6 +383,7 @@
'browser/chromeos/customization_document.h',
'browser/chromeos/dom_ui/system_options_handler.cc',
'browser/chromeos/dom_ui/system_options_handler.h',
+ 'browser/chromeos/drop_shadow_label.cc',
'browser/chromeos/external_cookie_handler.cc',
'browser/chromeos/external_cookie_handler.h',
'browser/chromeos/external_metrics.cc',
@@ -564,8 +565,12 @@
'browser/chromeos/wm_message_listener.h',
'browser/chromeos/wm_overview_controller.cc',
'browser/chromeos/wm_overview_controller.h',
+ 'browser/chromeos/wm_overview_fav_icon.cc',
+ 'browser/chromeos/wm_overview_fav_icon.h',
'browser/chromeos/wm_overview_snapshot.cc',
'browser/chromeos/wm_overview_snapshot.h',
+ 'browser/chromeos/wm_overview_title.cc',
+ 'browser/chromeos/wm_overview_title.h',
'browser/cocoa/about_ipc_bridge.h',
'browser/cocoa/about_ipc_bridge.mm',
'browser/cocoa/about_ipc_controller.h',
diff --git a/views/controls/label.cc b/views/controls/label.cc
index d30a62b..c842191 100644
--- a/views/controls/label.cc
+++ b/views/controls/label.cc
@@ -25,7 +25,7 @@ namespace views {
const char Label::kViewClassName[] = "views/Label";
SkColor Label::kEnabledColor, Label::kDisabledColor;
-static const int kFocusBorderPadding = 1;
+const int Label::kFocusBorderPadding = 1;
Label::Label() {
Init(std::wstring(), GetDefaultFont());
@@ -78,19 +78,12 @@ void Label::DidChangeBounds(const gfx::Rect& previous,
void Label::Paint(gfx::Canvas* canvas) {
PaintBackground(canvas);
+
std::wstring paint_text;
gfx::Rect text_bounds;
int flags = 0;
CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- canvas->DrawStringInt(paint_text, font_, color_,
- text_bounds.x(), text_bounds.y(),
- text_bounds.width(), text_bounds.height(), flags);
-
- if (HasFocus() || paint_as_focused_) {
- text_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding);
- canvas->DrawFocusRect(text_bounds.x(), text_bounds.y(),
- text_bounds.width(), text_bounds.height());
- }
+ PaintText(canvas, paint_text, text_bounds, flags);
}
void Label::PaintBackground(gfx::Canvas* canvas) {
@@ -266,6 +259,44 @@ void Label::SetHasFocusBorder(bool has_focus_border) {
text_size_valid_ &= !is_multi_line_;
}
+void Label::PaintText(gfx::Canvas* canvas,
+ const std::wstring& text,
+ const gfx::Rect& text_bounds,
+ int flags) {
+ canvas->DrawStringInt(text, font_, color_,
+ text_bounds.x(), text_bounds.y(),
+ text_bounds.width(), text_bounds.height(), flags);
+
+ if (HasFocus() || paint_as_focused_) {
+ gfx::Rect focus_bounds = text_bounds;
+ focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding);
+ canvas->DrawFocusRect(focus_bounds.x(), focus_bounds.y(),
+ focus_bounds.width(), focus_bounds.height());
+ }
+}
+
+gfx::Size Label::GetTextSize() const {
+ if (!text_size_valid_) {
+ // For single-line strings, we supply the largest possible width, because
+ // while adding NO_ELLIPSIS to the flags works on Windows for forcing
+ // SizeStringInt() to calculate the desired width, it doesn't seem to work
+ // on Linux.
+ int w = is_multi_line_ ?
+ GetAvailableRect().width() : std::numeric_limits<int>::max();
+ int h = font_.height();
+ // For single-line strings, ignore the available width and calculate how
+ // wide the text wants to be.
+ int flags = ComputeMultiLineFlags();
+ if (!is_multi_line_)
+ flags |= gfx::Canvas::NO_ELLIPSIS;
+ gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags);
+ text_size_.SetSize(w, h);
+ text_size_valid_ = true;
+ }
+
+ return text_size_;
+}
+
// static
gfx::Font Label::GetDefaultFont() {
return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
@@ -302,36 +333,6 @@ void Label::Init(const std::wstring& text, const gfx::Font& font) {
has_focus_border_ = false;
}
-void Label::CalculateDrawStringParams(std::wstring* paint_text,
- gfx::Rect* text_bounds,
- int* flags) const {
- DCHECK(paint_text && text_bounds && flags);
-
- if (url_set_) {
- // TODO(jungshik) : Figure out how to get 'intl.accept_languages'
- // preference and use it when calling ElideUrl.
- *paint_text = gfx::ElideUrl(url_, font_, width(), std::wstring());
-
- // An URLs is always treated as an LTR text and therefore we should
- // explicitly mark it as such if the locale is RTL so that URLs containing
- // Hebrew or Arabic characters are displayed correctly.
- //
- // Note that we don't check the View's UI layout setting in order to
- // determine whether or not to insert the special Unicode formatting
- // characters. We use the locale settings because an URL is always treated
- // as an LTR string, even if its containing view does not use an RTL UI
- // layout.
- base::i18n::GetDisplayStringInLTRDirectionality(paint_text);
- } else if (elide_in_middle_) {
- *paint_text = gfx::ElideText(text_, font_, width(), true);
- } else {
- *paint_text = text_;
- }
-
- *text_bounds = GetTextBounds();
- *flags = ComputeMultiLineFlags();
-}
-
void Label::UpdateContainsMouse(const MouseEvent& event) {
SetContainsMouse(GetTextBounds().Contains(event.x(), event.y()));
}
@@ -374,28 +375,6 @@ gfx::Rect Label::GetTextBounds() const {
return gfx::Rect(text_origin, text_size);
}
-gfx::Size Label::GetTextSize() const {
- if (!text_size_valid_) {
- // For single-line strings, we supply the largest possible width, because
- // while adding NO_ELLIPSIS to the flags works on Windows for forcing
- // SizeStringInt() to calculate the desired width, it doesn't seem to work
- // on Linux.
- int w = is_multi_line_ ?
- GetAvailableRect().width() : std::numeric_limits<int>::max();
- int h = font_.height();
- // For single-line strings, ignore the available width and calculate how
- // wide the text wants to be.
- int flags = ComputeMultiLineFlags();
- if (!is_multi_line_)
- flags |= gfx::Canvas::NO_ELLIPSIS;
- gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags);
- text_size_.SetSize(w, h);
- text_size_valid_ = true;
- }
-
- return text_size_;
-}
-
int Label::ComputeMultiLineFlags() const {
if (!is_multi_line_)
return 0;
@@ -432,4 +411,34 @@ gfx::Rect Label::GetAvailableRect() const {
return bounds;
}
+void Label::CalculateDrawStringParams(std::wstring* paint_text,
+ gfx::Rect* text_bounds,
+ int* flags) const {
+ DCHECK(paint_text && text_bounds && flags);
+
+ if (url_set_) {
+ // TODO(jungshik) : Figure out how to get 'intl.accept_languages'
+ // preference and use it when calling ElideUrl.
+ *paint_text = gfx::ElideUrl(url_, font_, width(), std::wstring());
+
+ // An URLs is always treated as an LTR text and therefore we should
+ // explicitly mark it as such if the locale is RTL so that URLs containing
+ // Hebrew or Arabic characters are displayed correctly.
+ //
+ // Note that we don't check the View's UI layout setting in order to
+ // determine whether or not to insert the special Unicode formatting
+ // characters. We use the locale settings because an URL is always treated
+ // as an LTR string, even if its containing view does not use an RTL UI
+ // layout.
+ base::i18n::GetDisplayStringInLTRDirectionality(paint_text);
+ } else if (elide_in_middle_) {
+ *paint_text = gfx::ElideText(text_, font_, width(), true);
+ } else {
+ *paint_text = text_;
+ }
+
+ *text_bounds = GetTextBounds();
+ *flags = ComputeMultiLineFlags();
+}
+
} // namespace views
diff --git a/views/controls/label.h b/views/controls/label.h
index a749be8..30bd1b4 100644
--- a/views/controls/label.h
+++ b/views/controls/label.h
@@ -45,6 +45,9 @@ class Label : public View {
// The view class name.
static const char kViewClassName[];
+ // The padding for the focus border when rendering focused text.
+ static const int kFocusBorderPadding;
+
Label();
explicit Label(const std::wstring& text);
Label(const std::wstring& text, const gfx::Font& font);
@@ -186,12 +189,25 @@ class Label : public View {
void set_collapse_when_hidden(bool value) { collapse_when_hidden_ = value; }
bool collapse_when_hidden() const { return collapse_when_hidden_; }
+ // Gets/set whether or not this label is to be painted as a focused element.
void set_paint_as_focused(bool paint_as_focused) {
paint_as_focused_ = paint_as_focused;
}
+ bool paint_as_focused() const { return paint_as_focused_; }
void SetHasFocusBorder(bool has_focus_border);
+ protected:
+ // Called by Paint to paint the text. Override this to change how
+ // text is painted.
+ virtual void PaintText(gfx::Canvas* canvas,
+ const std::wstring& text,
+ const gfx::Rect& text_bounds,
+ int flags);
+
+ void invalidate_text_size() { text_size_valid_ = false; }
+
+ virtual gfx::Size GetTextSize() const;
private:
// These tests call CalculateDrawStringParams in order to verify the
// calculations done for drawing text.
@@ -204,11 +220,6 @@ class Label : public View {
void Init(const std::wstring& text, const gfx::Font& font);
- // Returns parameters to be used for the DrawString call.
- void CalculateDrawStringParams(std::wstring* paint_text,
- gfx::Rect* text_bounds,
- int* flags) const;
-
// If the mouse is over the text, SetContainsMouse(true) is invoked, otherwise
// SetContainsMouse(false) is invoked.
void UpdateContainsMouse(const MouseEvent& event);
@@ -221,12 +232,15 @@ class Label : public View {
// Returns where the text is drawn, in the receivers coordinate system.
gfx::Rect GetTextBounds() const;
- gfx::Size GetTextSize() const;
-
int ComputeMultiLineFlags() const;
gfx::Rect GetAvailableRect() const;
+ // Returns parameters to be used for the DrawString call.
+ void CalculateDrawStringParams(std::wstring* paint_text,
+ gfx::Rect* text_bounds,
+ int* flags) const;
+
// The colors to use for enabled and disabled labels.
static SkColor kEnabledColor, kDisabledColor;