Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / star_view.cc
blob4f0660e7ff2399874f2ecf2f50ec577d14c44653
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.
5 #include "chrome/browser/ui/views/location_bar/star_view.h"
7 #include "base/metrics/histogram.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/bookmarks/bookmark_stats.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/view_ids.h"
14 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "grit/theme_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/material_design/material_design_controller.h"
19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/paint_vector_icon.h"
21 #include "ui/gfx/vector_icons_public.h"
22 #include "ui/native_theme/common_theme.h"
23 #include "ui/native_theme/native_theme.h"
25 StarView::StarView(CommandUpdater* command_updater, Browser* browser)
26 : BubbleIconView(command_updater, IDC_BOOKMARK_PAGE), browser_(browser) {
27 set_id(VIEW_ID_STAR_BUTTON);
28 SetToggled(false);
29 // Compensate for the difference between the material icon grid and the
30 // Chrome icon grid.
31 if (ui::MaterialDesignController::IsModeMaterial())
32 SetBorder(views::Border::CreateEmptyBorder(0, -1, 0, -1));
35 StarView::~StarView() {}
37 void StarView::SetToggled(bool on) {
38 SetTooltipText(l10n_util::GetStringUTF16(
39 on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR));
41 if (ui::MaterialDesignController::IsModeMaterial()) {
42 SkColor icon_color;
43 ui::CommonThemeGetSystemColor(on ? ui::NativeTheme::kColorId_GoogleBlue
44 : ui::NativeTheme::kColorId_ChromeIconGrey,
45 &icon_color);
46 SetImage(gfx::CreateVectorIcon(
47 on ? gfx::VectorIconId::STAR : gfx::VectorIconId::STAR_BORDER, 18,
48 icon_color));
49 } else {
50 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
51 on ? IDR_STAR_LIT : IDR_STAR));
55 void StarView::OnExecuting(
56 BubbleIconView::ExecuteSource execute_source) {
57 BookmarkEntryPoint entry_point = BOOKMARK_ENTRY_POINT_STAR_MOUSE;
58 switch (execute_source) {
59 case EXECUTE_SOURCE_MOUSE:
60 entry_point = BOOKMARK_ENTRY_POINT_STAR_MOUSE;
61 break;
62 case EXECUTE_SOURCE_KEYBOARD:
63 entry_point = BOOKMARK_ENTRY_POINT_STAR_KEY;
64 break;
65 case EXECUTE_SOURCE_GESTURE:
66 entry_point = BOOKMARK_ENTRY_POINT_STAR_GESTURE;
67 break;
69 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
70 entry_point,
71 BOOKMARK_ENTRY_POINT_LIMIT);
74 void StarView::ExecuteCommand(ExecuteSource source) {
75 if (browser_) {
76 OnExecuting(source);
77 chrome::BookmarkCurrentPageIgnoringExtensionOverrides(browser_);
78 } else {
79 BubbleIconView::ExecuteCommand(source);
83 views::BubbleDelegateView* StarView::GetBubble() const {
84 return BookmarkBubbleView::bookmark_bubble();