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#include "ui/base/accessibility/accessible_view_state.h" 10 11PageActionWithBadgeView::PageActionWithBadgeView( 12 PageActionImageView* image_view) { 13 image_view_ = image_view; 14 AddChildView(image_view_); 15} 16 17void PageActionWithBadgeView::GetAccessibleState( 18 ui::AccessibleViewState* state) { 19 state->role = ui::AccessibilityTypes::ROLE_GROUPING; 20} 21 22gfx::Size PageActionWithBadgeView::GetPreferredSize() { 23 return gfx::Size(Extension::kPageActionIconMaxSize, 24 Extension::kPageActionIconMaxSize); 25} 26 27void PageActionWithBadgeView::Layout() { 28 // We have 25 pixels of vertical space in the Omnibox to play with, so even 29 // sized icons (such as 16x16) have either a 5 or a 4 pixel whitespace 30 // (padding) above and below. It looks better to have the extra pixel above 31 // the icon than below it, so we add a pixel. http://crbug.com/25708. 32 const SkBitmap& image = image_view()->GetImage(); 33 int y = (image.height() + 1) % 2; // Even numbers: 1px padding. Odd: 0px. 34 image_view_->SetBounds(0, y, width(), height()); 35} 36 37void PageActionWithBadgeView::UpdateVisibility(TabContents* contents, 38 const GURL& url) { 39 image_view_->UpdateVisibility(contents, url); 40 SetVisible(image_view_->IsVisible()); 41} 42