Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(965)

Side by Side Diff: chrome/browser/accessibility/invert_bubble_views.cc

Issue 10419002: browser: Move invert_bubble_views.{cc,h} into views/ directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 "base/utf_string_conversions.h"
6 #include "chrome/browser/accessibility/invert_bubble_views.h"
7 #include "chrome/browser/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/views/event_utils.h"
13 #include "chrome/common/pref_names.h"
14 #include "content/public/browser/page_navigator.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/sys_color_change_listener.h"
19 #include "ui/views/bubble/bubble_delegate.h"
20 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/link.h"
22 #include "ui/views/controls/link_listener.h"
23 #include "ui/views/layout/grid_layout.h"
24 #include "ui/views/layout/layout_constants.h"
25
26 namespace {
27 const char kHighContrastExtensionUrl[] = "https://chrome.google.com/webstore/det ail/djcfdncoelnlbldjfhinnjlhdjlikmph";
28 const char kDarkThemeSearchUrl[] = "https://chrome.google.com/webstore/search-th emes/dark";
29 const char kLearnMoreUrl[] = "https://groups.google.com/a/googleproductforums.co m/d/topic/chrome/Xrco2HsXS-8/discussion";
30 const int kBubbleWidth = 500;
31 } // namespace
32
33 class InvertBubbleView : public views::BubbleDelegateView,
34 public views::LinkListener {
35 public:
36 InvertBubbleView(Profile* profile, views::View* anchor_view);
37 virtual ~InvertBubbleView();
38
39 protected:
40 // views::BubbleDelegateView overrides:
41 virtual void Init() OVERRIDE;
42
43 // views::BubbleDelegateView overrides:
44 virtual gfx::Rect GetAnchorRect() OVERRIDE;
45
46 // views::LinkListener overrides:
47 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
48
49 void OpenLink(const std::string& url, int event_flags);
50
51 Profile* profile_;
52 views::Link* high_contrast_;
53 views::Link* dark_theme_;
54 views::Link* learn_more_;
55 views::Link* close_;
56
57 DISALLOW_COPY_AND_ASSIGN(InvertBubbleView);
58 };
59
60 InvertBubbleView::InvertBubbleView(Profile* profile, views::View* anchor_view)
61 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
62 profile_(profile) {
63 }
64
65 InvertBubbleView::~InvertBubbleView() {
66 }
67
68 void InvertBubbleView::Init() {
69 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
70 const gfx::Font& original_font = rb.GetFont(ResourceBundle::MediumFont);
71
72 views::Label* title = new views::Label(
73 l10n_util::GetStringUTF16(IDS_HIGH_CONTRAST_NOTIFICATION));
74 title->SetFont(original_font.DeriveFont(2, gfx::Font::BOLD));
75 title->SetMultiLine(true);
76 title->SizeToFit(kBubbleWidth);
77
78 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
79 learn_more_->SetFont(original_font);
80 learn_more_->set_listener(this);
81
82 high_contrast_ =
83 new views::Link(l10n_util::GetStringUTF16(IDS_HIGH_CONTRAST_EXT));
84 high_contrast_->SetFont(original_font);
85 high_contrast_->set_listener(this);
86
87 dark_theme_ =
88 new views::Link(l10n_util::GetStringUTF16(IDS_DARK_THEME));
89 dark_theme_->SetFont(original_font);
90 dark_theme_->set_listener(this);
91
92 close_ = new views::Link(l10n_util::GetStringUTF16(IDS_CLOSE));
93 close_->SetFont(original_font);
94 close_->set_listener(this);
95
96 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
97 SetLayoutManager(layout);
98
99 views::ColumnSet* columns = layout->AddColumnSet(0);
100 for (int i = 0; i < 4; i++) {
101 columns->AddColumn(views::GridLayout::LEADING,
102 views::GridLayout::LEADING, 0,
103 views::GridLayout::USE_PREF, 0, 0);
104 }
105
106 layout->StartRow(0, 0);
107 layout->AddView(title, 4, 1);
108 layout->StartRowWithPadding(0, 0, 0,
109 views::kRelatedControlSmallVerticalSpacing);
110 layout->AddView(high_contrast_);
111 layout->AddView(dark_theme_);
112 layout->AddView(learn_more_);
113 layout->AddView(close_);
114
115 // Switching to high-contrast mode has a nasty habit of causing Chrome
116 // top-level windows to lose focus, so closing the bubble on deactivate
117 // makes it disappear before the user has even seen it. This forces the
118 // user to close it explicitly, which should be okay because it affects
119 // a small minority of users, and only once.
120 set_close_on_deactivate(false);
121 set_move_with_anchor(true);
122 }
123
124 gfx::Rect InvertBubbleView::GetAnchorRect() {
125 // Set the height to 0 so we display the bubble at the top of the
126 // anchor rect.
127 gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
128 rect.set_height(0);
129 return rect;
130 }
131
132 void InvertBubbleView::LinkClicked(views::Link* source, int event_flags) {
133 if (source == high_contrast_)
134 OpenLink(kHighContrastExtensionUrl, event_flags);
135 else if (source == dark_theme_)
136 OpenLink(kDarkThemeSearchUrl, event_flags);
137 else if (source == learn_more_)
138 OpenLink(kLearnMoreUrl, event_flags);
139 else if (source == close_)
140 GetWidget()->Close();
141 else
142 NOTREACHED();
143 }
144
145 void InvertBubbleView::OpenLink(const std::string& url, int event_flags) {
146 Browser* browser = browser::FindLastActiveWithProfile(profile_);
147 if (browser) {
148 WindowOpenDisposition disposition =
149 event_utils::DispositionFromEventFlags(event_flags);
150 content::OpenURLParams params(
151 GURL(url), content::Referrer(),
152 disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition,
153 content::PAGE_TRANSITION_LINK, false);
154 browser->OpenURL(params);
155 }
156 }
157
158 void InvertBubble::MaybeShowInvertBubble(Profile* profile,
159 views::View* anchor_view) {
160 PrefService* pref_service = profile->GetPrefs();
161 if (gfx::IsInvertedColorScheme() &&
162 !pref_service->GetBoolean(prefs::kInvertNotificationShown)) {
163 pref_service->SetBoolean(prefs::kInvertNotificationShown, true);
164 InvertBubbleView* delegate = new InvertBubbleView(profile, anchor_view);
165 views::BubbleDelegateView::CreateBubble(delegate);
166 delegate->StartFade(true);
167 }
168 }
OLDNEW
« no previous file with comments | « chrome/browser/accessibility/invert_bubble_views.h ('k') | chrome/browser/ui/views/accessibility/invert_bubble_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698