Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/views/location_bar_view.h" | 5 #include "chrome/browser/views/location_bar_view.h" |
| 6 | 6 |
| 7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 return std::wstring(); | 68 return std::wstring(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 // PageActionWithBadgeView ---------------------------------------------------- | 72 // PageActionWithBadgeView ---------------------------------------------------- |
| 73 | 73 |
| 74 // A container for the PageActionImageView plus its badge. | 74 // A container for the PageActionImageView plus its badge. |
| 75 class LocationBarView::PageActionWithBadgeView : public views::View { | 75 class LocationBarView::PageActionWithBadgeView : public views::View { |
| 76 public: | 76 public: |
| 77 explicit PageActionWithBadgeView(PageActionImageView* image_view); | 77 explicit PageActionWithBadgeView(PageActionImageView* image_view); |
| 78 virtual ~PageActionWithBadgeView() {} | |
|
Aaron Boodman
2010/01/21 23:10:58
~View is virtual so I don't think this is necessar
| |
| 78 | 79 |
| 79 PageActionImageView* image_view() { return image_view_; } | 80 PageActionImageView* image_view() { return image_view_; } |
| 80 | 81 |
| 81 virtual gfx::Size GetPreferredSize() { | 82 virtual gfx::Size GetPreferredSize() { |
| 82 return gfx::Size(Extension::kPageActionIconMaxSize, | 83 return gfx::Size(Extension::kPageActionIconMaxSize, |
| 83 Extension::kPageActionIconMaxSize); | 84 Extension::kPageActionIconMaxSize); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void UpdateVisibility(TabContents* contents, const GURL& url); | 87 void UpdateVisibility(TabContents* contents, const GURL& url); |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 virtual void Layout(); | 90 virtual void Layout(); |
| 90 | 91 |
| 91 // Override PaintChildren so that we can paint the badge on top of children. | |
| 92 virtual void PaintChildren(gfx::Canvas* canvas); | |
| 93 | |
| 94 // The button this view contains. | 92 // The button this view contains. |
| 95 PageActionImageView* image_view_; | 93 PageActionImageView* image_view_; |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(PageActionWithBadgeView); | |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 LocationBarView::PageActionWithBadgeView::PageActionWithBadgeView( | 98 LocationBarView::PageActionWithBadgeView::PageActionWithBadgeView( |
| 99 PageActionImageView* image_view) { | 99 PageActionImageView* image_view) { |
| 100 image_view_ = image_view; | 100 image_view_ = image_view; |
| 101 AddChildView(image_view_); | 101 AddChildView(image_view_); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void LocationBarView::PageActionWithBadgeView::Layout() { | 104 void LocationBarView::PageActionWithBadgeView::Layout() { |
| 105 // We have 25 pixels of vertical space in the Omnibox to play with, so even | 105 // We have 25 pixels of vertical space in the Omnibox to play with, so even |
| 106 // sized icons (such as 16x16) have either a 5 or a 4 pixel whitespace | 106 // sized icons (such as 16x16) have either a 5 or a 4 pixel whitespace |
| 107 // (padding) above and below. It looks better to have the extra pixel above | 107 // (padding) above and below. It looks better to have the extra pixel above |
| 108 // the icon than below it, so we add a pixel. http://crbug.com/25708. | 108 // the icon than below it, so we add a pixel. http://crbug.com/25708. |
| 109 const SkBitmap& image = image_view()->GetImage(); | 109 const SkBitmap& image = image_view()->GetImage(); |
| 110 int y = (image.height() + 1) % 2; // Even numbers: 1px padding. Odd: 0px. | 110 int y = (image.height() + 1) % 2; // Even numbers: 1px padding. Odd: 0px. |
| 111 image_view_->SetBounds(0, y, width(), height()); | 111 image_view_->SetBounds(0, y, width(), height()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void LocationBarView::PageActionWithBadgeView::PaintChildren( | |
| 115 gfx::Canvas* canvas) { | |
| 116 View::PaintChildren(canvas); | |
| 117 | |
| 118 ExtensionAction* action = image_view_->page_action(); | |
| 119 int tab_id = image_view_->current_tab_id(); | |
| 120 if (tab_id < 0) | |
| 121 return; | |
| 122 | |
| 123 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id); | |
| 124 } | |
| 125 | |
| 126 void LocationBarView::PageActionWithBadgeView::UpdateVisibility( | 114 void LocationBarView::PageActionWithBadgeView::UpdateVisibility( |
| 127 TabContents* contents, const GURL& url) { | 115 TabContents* contents, const GURL& url) { |
| 128 image_view_->UpdateVisibility(contents, url); | 116 image_view_->UpdateVisibility(contents, url); |
| 129 SetVisible(image_view_->IsVisible()); | 117 SetVisible(image_view_->IsVisible()); |
| 130 } | 118 } |
| 131 | 119 |
| 132 | 120 |
| 133 // LocationBarView ----------------------------------------------------------- | 121 // LocationBarView ----------------------------------------------------------- |
| 134 | 122 |
| 135 LocationBarView::LocationBarView(Profile* profile, | 123 LocationBarView::LocationBarView(Profile* profile, |
| (...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1621 const int button = 1; // Left mouse button. | 1609 const int button = 1; // Left mouse button. |
| 1622 page_action_views_[i]->image_view()->ExecuteAction(button); | 1610 page_action_views_[i]->image_view()->ExecuteAction(button); |
| 1623 return; | 1611 return; |
| 1624 } | 1612 } |
| 1625 ++current; | 1613 ++current; |
| 1626 } | 1614 } |
| 1627 } | 1615 } |
| 1628 } | 1616 } |
| 1629 NOTREACHED(); | 1617 NOTREACHED(); |
| 1630 } | 1618 } |
| OLD | NEW |