1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_
8 #include "chrome/browser/safe_browsing/ui_manager.h"
9 #include "chrome/browser/ui/toolbar/toolbar_model.h"
10 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
11 #include "ui/views/controls/button/button.h"
12 #include "ui/views/controls/button/label_button.h"
14 class LocationBarView
;
15 class OriginChipExtensionIcon
;
33 class OriginChipView
: public views::LabelButton
,
34 public views::ButtonListener
,
35 public SafeBrowsingUIManager::Observer
{
37 OriginChipView(LocationBarView
* location_bar_view
,
39 const gfx::FontList
& font_list
);
40 virtual ~OriginChipView();
42 // Recalculates the contents of the Origin Chip based on the displayed tab.
43 void Update(content::WebContents
* tab
);
45 // Called to signal that the contents of the tab being shown has changed, so
46 // the origin chip needs to update itself to the new state.
49 views::ImageView
* location_icon_view() {
50 return location_icon_view_
;
52 const views::ImageView
* location_icon_view() const {
53 return location_icon_view_
;
56 // Elides the hostname shown to the indicated width, if needed. Returns the
57 // final width of the origin chip. Note: this may be more than the target
58 // width, since the hostname will not be elided past the TLD+1.
59 int ElideDomainTarget(int target_max_width
);
61 // Starts an animation that fades in the border.
64 // Returns the current X position of the host label.
65 int host_label_x() const { return host_label_
->x(); }
67 // views::LabelButton:
68 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
71 // Sets an image grid to represent the current security state.
72 void SetBorderImages(const int images
[3][9]);
74 // views::LabelButton:
75 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
76 virtual void AnimationEnded(const gfx::Animation
* animation
) OVERRIDE
;
77 virtual void Layout() OVERRIDE
;
78 virtual void OnPaintBorder(gfx::Canvas
* canvas
) OVERRIDE
;
80 // views::ButtonListener:
81 virtual void ButtonPressed(views::Button
* sender
,
82 const ui::Event
& event
) OVERRIDE
;
84 // SafeBrowsingUIManager::Observer:
85 virtual void OnSafeBrowsingHit(
86 const SafeBrowsingUIManager::UnsafeResource
& resource
) OVERRIDE
;
87 virtual void OnSafeBrowsingMatch(
88 const SafeBrowsingUIManager::UnsafeResource
& resource
) OVERRIDE
;
90 LocationBarView
* location_bar_view_
;
92 views::Label
* host_label_
;
93 LocationIconView
* location_icon_view_
;
94 bool showing_16x16_icon_
;
95 scoped_ptr
<OriginChipExtensionIcon
> extension_icon_
;
97 ToolbarModel::SecurityLevel security_level_
;
99 scoped_ptr
<gfx::SlideAnimation
> fade_in_animation_
;
101 DISALLOW_COPY_AND_ASSIGN(OriginChipView
);
104 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ORIGIN_CHIP_VIEW_H_