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