OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" |
| 6 |
5 #include "base/utf_string_conversions.h" | 7 #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/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
11 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
12 #include "chrome/browser/ui/views/event_utils.h" | 13 #include "chrome/browser/ui/views/event_utils.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 #include "content/public/browser/page_navigator.h" | 15 #include "content/public/browser/page_navigator.h" |
15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/gfx/sys_color_change_listener.h" | 19 #include "ui/gfx/sys_color_change_listener.h" |
19 #include "ui/views/bubble/bubble_delegate.h" | 20 #include "ui/views/bubble/bubble_delegate.h" |
20 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
21 #include "ui/views/controls/link.h" | 22 #include "ui/views/controls/link.h" |
22 #include "ui/views/controls/link_listener.h" | 23 #include "ui/views/controls/link_listener.h" |
23 #include "ui/views/layout/grid_layout.h" | 24 #include "ui/views/layout/grid_layout.h" |
24 #include "ui/views/layout/layout_constants.h" | 25 #include "ui/views/layout/layout_constants.h" |
25 | 26 |
26 namespace { | 27 namespace { |
| 28 |
27 const char kHighContrastExtensionUrl[] = "https://chrome.google.com/webstore/det
ail/djcfdncoelnlbldjfhinnjlhdjlikmph"; | 29 const char kHighContrastExtensionUrl[] = "https://chrome.google.com/webstore/det
ail/djcfdncoelnlbldjfhinnjlhdjlikmph"; |
28 const char kDarkThemeSearchUrl[] = "https://chrome.google.com/webstore/search-th
emes/dark"; | 30 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"; | 31 const char kLearnMoreUrl[] = "https://groups.google.com/a/googleproductforums.co
m/d/topic/chrome/Xrco2HsXS-8/discussion"; |
30 const int kBubbleWidth = 500; | 32 const int kBubbleWidth = 500; |
31 } // namespace | |
32 | 33 |
33 class InvertBubbleView : public views::BubbleDelegateView, | 34 class InvertBubbleView : public views::BubbleDelegateView, |
34 public views::LinkListener { | 35 public views::LinkListener { |
35 public: | 36 public: |
36 InvertBubbleView(Profile* profile, views::View* anchor_view); | 37 InvertBubbleView(Profile* profile, views::View* anchor_view); |
37 virtual ~InvertBubbleView(); | 38 virtual ~InvertBubbleView(); |
38 | 39 |
39 protected: | 40 protected: |
40 // views::BubbleDelegateView overrides: | 41 // Overridden from views::BubbleDelegateView: |
41 virtual void Init() OVERRIDE; | 42 virtual void Init() OVERRIDE; |
42 | |
43 // views::BubbleDelegateView overrides: | |
44 virtual gfx::Rect GetAnchorRect() OVERRIDE; | 43 virtual gfx::Rect GetAnchorRect() OVERRIDE; |
45 | 44 |
46 // views::LinkListener overrides: | 45 // Overridden from views::LinkListener: |
47 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | 46 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
48 | 47 |
49 void OpenLink(const std::string& url, int event_flags); | 48 void OpenLink(const std::string& url, int event_flags); |
50 | 49 |
51 Profile* profile_; | 50 Profile* profile_; |
52 views::Link* high_contrast_; | 51 views::Link* high_contrast_; |
53 views::Link* dark_theme_; | 52 views::Link* dark_theme_; |
54 views::Link* learn_more_; | 53 views::Link* learn_more_; |
55 views::Link* close_; | 54 views::Link* close_; |
56 | 55 |
57 DISALLOW_COPY_AND_ASSIGN(InvertBubbleView); | 56 DISALLOW_COPY_AND_ASSIGN(InvertBubbleView); |
58 }; | 57 }; |
59 | 58 |
60 InvertBubbleView::InvertBubbleView(Profile* profile, views::View* anchor_view) | 59 InvertBubbleView::InvertBubbleView(Profile* profile, views::View* anchor_view) |
61 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 60 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
62 profile_(profile) { | 61 profile_(profile) { |
63 } | 62 } |
64 | 63 |
65 InvertBubbleView::~InvertBubbleView() { | 64 InvertBubbleView::~InvertBubbleView() { |
66 } | 65 } |
67 | 66 |
68 void InvertBubbleView::Init() { | 67 void InvertBubbleView::Init() { |
69 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 68 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
70 const gfx::Font& original_font = rb.GetFont(ResourceBundle::MediumFont); | 69 const gfx::Font& original_font = rb.GetFont(ui::ResourceBundle::MediumFont); |
71 | 70 |
72 views::Label* title = new views::Label( | 71 views::Label* title = new views::Label( |
73 l10n_util::GetStringUTF16(IDS_HIGH_CONTRAST_NOTIFICATION)); | 72 l10n_util::GetStringUTF16(IDS_HIGH_CONTRAST_NOTIFICATION)); |
74 title->SetFont(original_font.DeriveFont(2, gfx::Font::BOLD)); | 73 title->SetFont(original_font.DeriveFont(2, gfx::Font::BOLD)); |
75 title->SetMultiLine(true); | 74 title->SetMultiLine(true); |
76 title->SizeToFit(kBubbleWidth); | 75 title->SizeToFit(kBubbleWidth); |
77 | 76 |
78 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 77 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
79 learn_more_->SetFont(original_font); | 78 learn_more_->SetFont(original_font); |
80 learn_more_->set_listener(this); | 79 learn_more_->set_listener(this); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 WindowOpenDisposition disposition = | 147 WindowOpenDisposition disposition = |
149 event_utils::DispositionFromEventFlags(event_flags); | 148 event_utils::DispositionFromEventFlags(event_flags); |
150 content::OpenURLParams params( | 149 content::OpenURLParams params( |
151 GURL(url), content::Referrer(), | 150 GURL(url), content::Referrer(), |
152 disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition, | 151 disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition, |
153 content::PAGE_TRANSITION_LINK, false); | 152 content::PAGE_TRANSITION_LINK, false); |
154 browser->OpenURL(params); | 153 browser->OpenURL(params); |
155 } | 154 } |
156 } | 155 } |
157 | 156 |
158 void InvertBubble::MaybeShowInvertBubble(Profile* profile, | 157 } // namespace |
159 views::View* anchor_view) { | 158 |
| 159 namespace browser { |
| 160 |
| 161 void MaybeShowInvertBubbleView(Profile* profile, views::View* anchor_view) { |
160 PrefService* pref_service = profile->GetPrefs(); | 162 PrefService* pref_service = profile->GetPrefs(); |
161 if (gfx::IsInvertedColorScheme() && | 163 if (gfx::IsInvertedColorScheme() && |
162 !pref_service->GetBoolean(prefs::kInvertNotificationShown)) { | 164 !pref_service->GetBoolean(prefs::kInvertNotificationShown)) { |
163 pref_service->SetBoolean(prefs::kInvertNotificationShown, true); | 165 pref_service->SetBoolean(prefs::kInvertNotificationShown, true); |
164 InvertBubbleView* delegate = new InvertBubbleView(profile, anchor_view); | 166 InvertBubbleView* delegate = new InvertBubbleView(profile, anchor_view); |
165 views::BubbleDelegateView::CreateBubble(delegate); | 167 views::BubbleDelegateView::CreateBubble(delegate); |
166 delegate->StartFade(true); | 168 delegate->StartFade(true); |
167 } | 169 } |
168 } | 170 } |
| 171 |
| 172 } // namespace browser |
OLD | NEW |