OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/location_bar/page_action_with_badge_view.h" | 5 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_action.h" | 7 #include "chrome/browser/extensions/extension_action.h" |
8 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 8 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
9 #include "ui/accessibility/ax_view_state.h" | 9 #include "ui/accessibility/ax_view_state.h" |
10 | 10 |
11 using content::WebContents; | 11 using content::WebContents; |
12 | 12 |
13 PageActionWithBadgeView::PageActionWithBadgeView( | 13 PageActionWithBadgeView::PageActionWithBadgeView( |
14 PageActionImageView* image_view) { | 14 PageActionImageView* image_view) { |
15 image_view_ = image_view; | 15 image_view_ = image_view; |
16 AddChildView(image_view_); | 16 AddChildView(image_view_); |
17 } | 17 } |
18 | 18 |
19 void PageActionWithBadgeView::GetAccessibleState( | 19 void PageActionWithBadgeView::GetAccessibleState( |
20 ui::AXViewState* state) { | 20 ui::AXViewState* state) { |
21 state->role = ui::AX_ROLE_GROUP; | 21 state->role = ui::AX_ROLE_GROUP; |
22 } | 22 } |
23 | 23 |
24 gfx::Size PageActionWithBadgeView::GetPreferredSize() { | 24 gfx::Size PageActionWithBadgeView::GetPreferredSize() const { |
25 return gfx::Size(ExtensionAction::kPageActionIconMaxSize, | 25 return gfx::Size(ExtensionAction::kPageActionIconMaxSize, |
26 ExtensionAction::kPageActionIconMaxSize); | 26 ExtensionAction::kPageActionIconMaxSize); |
27 } | 27 } |
28 | 28 |
29 void PageActionWithBadgeView::Layout() { | 29 void PageActionWithBadgeView::Layout() { |
30 // We have 25 pixels of vertical space in the Omnibox to play with, so even | 30 // We have 25 pixels of vertical space in the Omnibox to play with, so even |
31 // sized icons (such as 16x16) have either a 5 or a 4 pixel whitespace | 31 // sized icons (such as 16x16) have either a 5 or a 4 pixel whitespace |
32 // (padding) above and below. It looks better to have the extra pixel above | 32 // (padding) above and below. It looks better to have the extra pixel above |
33 // the icon than below it, so we add a pixel. http://crbug.com/25708. | 33 // the icon than below it, so we add a pixel. http://crbug.com/25708. |
34 const gfx::ImageSkia& image = image_view()->GetImage(); | 34 const gfx::ImageSkia& image = image_view()->GetImage(); |
35 int y = (image.height() + 1) % 2; // Even numbers: 1px padding. Odd: 0px. | 35 int y = (image.height() + 1) % 2; // Even numbers: 1px padding. Odd: 0px. |
36 image_view_->SetBounds(0, y, width(), height()); | 36 image_view_->SetBounds(0, y, width(), height()); |
37 } | 37 } |
38 | 38 |
39 void PageActionWithBadgeView::UpdateVisibility(WebContents* contents, | 39 void PageActionWithBadgeView::UpdateVisibility(WebContents* contents, |
40 const GURL& url) { | 40 const GURL& url) { |
41 image_view_->UpdateVisibility(contents, url); | 41 image_view_->UpdateVisibility(contents, url); |
42 SetVisible(image_view_->visible()); | 42 SetVisible(image_view_->visible()); |
43 } | 43 } |
OLD | NEW |