page_action_with_badge_view.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 6 7#include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 8#include "chrome/common/extensions/extension.h" 9 10PageActionWithBadgeView::PageActionWithBadgeView( 11 PageActionImageView* image_view) { 12 image_view_ = image_view; 13 AddChildView(image_view_); 14} 15 16AccessibilityTypes::Role PageActionWithBadgeView::GetAccessibleRole() { 17 return AccessibilityTypes::ROLE_GROUPING; 18} 19 20gfx::Size PageActionWithBadgeView::GetPreferredSize() { 21 return gfx::Size(Extension::kPageActionIconMaxSize, 22 Extension::kPageActionIconMaxSize); 23} 24 25void PageActionWithBadgeView::Layout() { 26 // We have 25 pixels of vertical space in the Omnibox to play with, so even 27 // sized icons (such as 16x16) have either a 5 or a 4 pixel whitespace 28 // (padding) above and below. It looks better to have the extra pixel above 29 // the icon than below it, so we add a pixel. http://crbug.com/25708. 30 const SkBitmap& image = image_view()->GetImage(); 31 int y = (image.height() + 1) % 2; // Even numbers: 1px padding. Odd: 0px. 32 image_view_->SetBounds(0, y, width(), height()); 33} 34 35void PageActionWithBadgeView::UpdateVisibility(TabContents* contents, 36 const GURL& url) { 37 image_view_->UpdateVisibility(contents, url); 38 SetVisible(image_view_->IsVisible()); 39} 40