summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-20 22:57:14 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-20 22:57:14 +0000
commita9bbf25029416198769c3a002d496e02ac467c54 (patch)
tree40545ebed7d701783998e95bbd2bced958b2c778 /chrome/browser
parent51bd36619bfaa05e98b3a6f58d48aaca6a66e307 (diff)
downloadchromium_src-a9bbf25029416198769c3a002d496e02ac467c54.zip
chromium_src-a9bbf25029416198769c3a002d496e02ac467c54.tar.gz
chromium_src-a9bbf25029416198769c3a002d496e02ac467c54.tar.bz2
Fix drawing code for page action badges.
The badge can now extend beyond the boundary of the image. BUG=24644 Review URL: http://codereview.chromium.org/297014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29581 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc5
-rw-r--r--chrome/browser/views/location_bar_view.cc122
-rw-r--r--chrome/browser/views/location_bar_view.h10
3 files changed, 106 insertions, 31 deletions
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 3183ede..8648099 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -60,6 +60,9 @@ const int kHboxBorder = 4;
// Padding between the elements in the bar.
static const int kInnerPadding = 4;
+// The size of each button on the toolbar.
+static const int kButtonSize = 29;
+
// TODO(deanm): Eventually this should be painted with the background png
// image, but for now we get pretty close by just drawing a solid border.
const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4);
@@ -681,6 +684,8 @@ LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk(
last_icon_skbitmap_(NULL),
last_icon_pixbuf_(NULL) {
event_box_.Own(gtk_event_box_new());
+ gtk_widget_set_size_request(event_box_.get(), kButtonSize, kButtonSize);
+
// Make the event box not visible so it does not paint a background.
gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE);
g_signal_connect(event_box_.get(), "button-press-event",
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index e6ee32e..9ca58e8b 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -59,6 +59,9 @@ static const int kEntryPadding = 3;
// Padding between the entry and the leading/trailing views.
static const int kInnerPadding = 3;
+// The size (both dimensions) of the buttons for page actions.
+static const int kPageActionButtonSize = 29;
+
static const SkBitmap* kBackground = NULL;
static const SkBitmap* kPopupBackground = NULL;
@@ -83,6 +86,59 @@ static std::wstring GetKeywordName(Profile* profile,
return std::wstring();
}
+
+// PageActionWithBadgeView ----------------------------------------------------
+
+// A container for the PageActionImageView plus its badge.
+class LocationBarView::PageActionWithBadgeView : public views::View {
+ public:
+ PageActionWithBadgeView(PageActionImageView* image_view);
+
+ PageActionImageView* image_view() { return image_view_; }
+
+ virtual gfx::Size GetPreferredSize() {
+ return gfx::Size(kPageActionButtonSize, kPageActionButtonSize);
+ }
+
+ void UpdateVisibility(TabContents* contents, const GURL& url);
+
+ private:
+ virtual void Layout();
+
+ // Override PaintChildren so that we can paint the badge on top of children.
+ virtual void PaintChildren(gfx::Canvas* canvas);
+
+ // The button this view contains.
+ PageActionImageView* image_view_;
+};
+
+LocationBarView::PageActionWithBadgeView::PageActionWithBadgeView(
+ PageActionImageView* image_view) {
+ image_view_ = image_view;
+ AddChildView(image_view_);
+}
+
+void LocationBarView::PageActionWithBadgeView::Layout() {
+ image_view_->SetBounds(0, 0, width(), height());
+}
+
+void LocationBarView::PageActionWithBadgeView::PaintChildren(
+ gfx::Canvas* canvas) {
+ View::PaintChildren(canvas);
+ const ExtensionActionState* state = image_view_->GetPageActionState();
+ if (state)
+ state->PaintBadge(canvas, gfx::Rect(width(), height()));
+}
+
+void LocationBarView::PageActionWithBadgeView::UpdateVisibility(
+ TabContents* contents, const GURL& url) {
+ image_view_->UpdateVisibility(contents, url);
+ SetVisible(image_view_->IsVisible());
+}
+
+
+// LocationBarView -----------------------------------------------------------
+
LocationBarView::LocationBarView(Profile* profile,
CommandUpdater* command_updater,
ToolbarModel* model,
@@ -428,9 +484,9 @@ void LocationBarView::DoLayout(const bool force_layout) {
int entry_width = width() - (kEntryPadding * 2);
gfx::Size page_action_size;
- for (size_t i = 0; i < page_action_image_views_.size(); i++) {
- if (page_action_image_views_[i]->IsVisible()) {
- page_action_size = page_action_image_views_[i]->GetPreferredSize();
+ for (size_t i = 0; i < page_action_views_.size(); i++) {
+ if (page_action_views_[i]->IsVisible()) {
+ page_action_size = page_action_views_[i]->GetPreferredSize();
entry_width -= page_action_size.width() + kInnerPadding;
}
}
@@ -486,13 +542,13 @@ void LocationBarView::DoLayout(const bool force_layout) {
offset -= kInnerPadding;
}
- for (size_t i = 0; i < page_action_image_views_.size(); i++) {
- if (page_action_image_views_[i]->IsVisible()) {
- page_action_size = page_action_image_views_[i]->GetPreferredSize();
+ for (size_t i = 0; i < page_action_views_.size(); i++) {
+ if (page_action_views_[i]->IsVisible()) {
+ page_action_size = page_action_views_[i]->GetPreferredSize();
offset -= page_action_size.width();
- page_action_image_views_[i]->SetBounds(offset, location_y,
- page_action_size.width(),
- location_height);
+ page_action_views_[i]->SetBounds(offset, location_y,
+ page_action_size.width(),
+ location_height);
offset -= kInnerPadding;
}
}
@@ -628,12 +684,12 @@ void LocationBarView::SetSecurityIcon(ToolbarModel::Icon icon) {
}
void LocationBarView::DeletePageActionViews() {
- if (!page_action_image_views_.empty()) {
- for (size_t i = 0; i < page_action_image_views_.size(); ++i)
- RemoveChildView(page_action_image_views_[i]);
- STLDeleteContainerPointers(page_action_image_views_.begin(),
- page_action_image_views_.end());
- page_action_image_views_.clear();
+ if (!page_action_views_.empty()) {
+ for (size_t i = 0; i < page_action_views_.size(); ++i)
+ RemoveChildView(page_action_views_[i]);
+ STLDeleteContainerPointers(page_action_views_.begin(),
+ page_action_views_.end());
+ page_action_views_.clear();
}
}
@@ -644,26 +700,27 @@ void LocationBarView::RefreshPageActionViews() {
// On startup we sometimes haven't loaded any extensions. This makes sure
// we catch up when the extensions (and any page actions) load.
- if (page_actions.size() != page_action_image_views_.size()) {
+ if (page_actions.size() != page_action_views_.size()) {
DeletePageActionViews(); // Delete the old views (if any).
- page_action_image_views_.resize(page_actions.size());
+ page_action_views_.resize(page_actions.size());
for (size_t i = 0; i < page_actions.size(); ++i) {
- page_action_image_views_[i] = new PageActionImageView(this, profile_,
- page_actions[i], bubble_positioner_);
- page_action_image_views_[i]->SetVisible(false);
- page_action_image_views_[i]->SetParentOwned(false);
- AddChildView(page_action_image_views_[i]);
+ page_action_views_[i] = new PageActionWithBadgeView(
+ new PageActionImageView(this, profile_,
+ page_actions[i], bubble_positioner_));
+ page_action_views_[i]->SetVisible(false);
+ page_action_views_[i]->SetParentOwned(false);
+ AddChildView(page_action_views_[i]);
}
}
TabContents* contents = delegate_->GetTabContents();
- if (!page_action_image_views_.empty() && contents) {
+ if (!page_action_views_.empty() && contents) {
GURL url = GURL(WideToUTF8(model_->GetText()));
- for (size_t i = 0; i < page_action_image_views_.size(); i++)
- page_action_image_views_[i]->UpdateVisibility(contents, url);
+ for (size_t i = 0; i < page_action_views_.size(); i++)
+ page_action_views_[i]->UpdateVisibility(contents, url);
}
}
@@ -1239,6 +1296,15 @@ bool LocationBarView::PageActionImageView::OnMousePressed(
return true;
}
+const ExtensionActionState*
+ LocationBarView::PageActionImageView::GetPageActionState() {
+ TabContents* contents = owner_->delegate_->GetTabContents();
+ if (!contents)
+ return NULL;
+
+ return contents->GetPageActionState(page_action_);
+}
+
void LocationBarView::PageActionImageView::ShowInfoBubble() {
ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT));
}
@@ -1253,7 +1319,7 @@ void LocationBarView::PageActionImageView::OnImageLoaded(SkBitmap* image,
}
void LocationBarView::PageActionImageView::UpdateVisibility(
- TabContents* contents, GURL url) {
+ TabContents* contents, const GURL& url) {
// Save this off so we can pass it back to the extension when the action gets
// executed. See PageActionImageView::OnMousePressed.
current_tab_id_ = ExtensionTabUtil::GetTabId(contents);
@@ -1333,8 +1399,8 @@ void LocationBarView::Revert() {
int LocationBarView::PageActionVisibleCount() {
int result = 0;
- for (size_t i = 0; i < page_action_image_views_.size(); i++) {
- if (page_action_image_views_[i]->IsVisible())
+ for (size_t i = 0; i < page_action_views_.size(); i++) {
+ if (page_action_views_[i]->IsVisible())
++result;
}
return result;
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index 6290a99..f725057 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -154,7 +154,7 @@ class LocationBarView : public LocationBar,
virtual LocationBarTesting* GetLocationBarForTesting() { return this; }
// Overridden from LocationBarTesting:
- virtual int PageActionCount() { return page_action_image_views_.size(); }
+ virtual int PageActionCount() { return page_action_views_.size(); }
virtual int PageActionVisibleCount();
static const int kVertMargin;
@@ -351,6 +351,8 @@ class LocationBarView : public LocationBar,
const BubblePositioner* bubble_positioner);
virtual ~PageActionImageView();
+ const ExtensionActionState* GetPageActionState();
+
// Overridden from view for the mouse hovering.
virtual bool OnMousePressed(const views::MouseEvent& event);
@@ -364,7 +366,7 @@ class LocationBarView : public LocationBar,
// Called to notify the PageAction that it should determine whether to be
// visible or hidden. |contents| is the TabContents that is active, |url|
// is the current page URL.
- void UpdateVisibility(TabContents* contents, GURL url);
+ void UpdateVisibility(TabContents* contents, const GURL& url);
private:
// The location bar view that owns us.
@@ -397,6 +399,8 @@ class LocationBarView : public LocationBar,
};
friend class PageActionImageView;
+ class PageActionWithBadgeView;
+ friend class PageActionWithBadgeView;
// Both Layout and OnChanged call into this. This updates the contents
// of the 3 views: selected_keyword, keyword_hint and type_search_view. If
// force_layout is true, or one of these views has changed in such a way as
@@ -515,7 +519,7 @@ class LocationBarView : public LocationBar,
SecurityImageView security_image_view_;
// The page action icon views.
- std::vector<PageActionImageView*> page_action_image_views_;
+ std::vector<PageActionWithBadgeView*> page_action_views_;
// A label displayed after the lock icon to show some extra information.
views::Label info_label_;