| 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" | 5 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 11 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 10 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 11 #include "content/public/browser/page_navigator.h" | 13 #include "content/public/browser/page_navigator.h" |
| 12 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/base/window_open_disposition.h" | 17 #include "ui/base/window_open_disposition.h" |
| 16 #include "ui/gfx/sys_color_change_listener.h" | |
| 17 #include "ui/views/bubble/bubble_delegate.h" | 18 #include "ui/views/bubble/bubble_delegate.h" |
| 18 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 19 #include "ui/views/controls/link.h" | 20 #include "ui/views/controls/link.h" |
| 20 #include "ui/views/controls/link_listener.h" | 21 #include "ui/views/controls/link_listener.h" |
| 21 #include "ui/views/layout/grid_layout.h" | 22 #include "ui/views/layout/grid_layout.h" |
| 22 #include "ui/views/layout/layout_constants.h" | 23 #include "ui/views/layout/layout_constants.h" |
| 23 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kHighContrastExtensionUrl[] = | 28 const char kHighContrastExtensionUrl[] = |
| 28 "https://chrome.google.com/webstore/detail/djcfdncoelnlbldjfhinnjlhdjlikmph"
; | 29 "https://chrome.google.com/webstore/detail/djcfdncoelnlbldjfhinnjlhdjlikmph"
; |
| 29 const char kDarkThemeSearchUrl[] = | 30 const char kDarkThemeSearchUrl[] = |
| 30 "https://chrome.google.com/webstore/search-themes/dark"; | 31 "https://chrome.google.com/webstore/search-themes/dark"; |
| 31 const char kLearnMoreUrl[] = | 32 const char kLearnMoreUrl[] = |
| 32 "https://groups.google.com/a/googleproductforums.com/d/topic/chrome/Xrco2HsX
S-8/discussion"; | 33 "https://groups.google.com/a/googleproductforums.com/d/topic/chrome/Xrco2HsX
S-8/discussion"; |
| 33 const int kBubbleWidth = 500; | 34 const int kBubbleWidth = 500; |
| 34 | 35 |
| 35 class InvertBubbleView : public views::BubbleDelegateView, | 36 class InvertBubbleView : public views::BubbleDelegateView, |
| 36 public views::LinkListener { | 37 public views::LinkListener { |
| 37 public: | 38 public: |
| 38 InvertBubbleView(Browser* browser, views::View* anchor_view); | 39 InvertBubbleView(Browser* browser, views::View* anchor_view); |
| 39 virtual ~InvertBubbleView(); | 40 virtual ~InvertBubbleView(); |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 // Overridden from views::BubbleDelegateView: | 43 // Overridden from views::BubbleDelegateView: |
| 43 virtual void Init() OVERRIDE; | 44 virtual void Init() OVERRIDE; |
| 44 virtual gfx::Rect GetAnchorRect() OVERRIDE; | |
| 45 | 45 |
| 46 // Overridden from views::LinkListener: | 46 // Overridden from views::LinkListener: |
| 47 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | 47 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
| 48 | 48 |
| 49 void OpenLink(const std::string& url, int event_flags); | 49 void OpenLink(const std::string& url, int event_flags); |
| 50 | 50 |
| 51 Browser* browser_; | 51 Browser* browser_; |
| 52 views::Link* high_contrast_; | 52 views::Link* high_contrast_; |
| 53 views::Link* dark_theme_; | 53 views::Link* dark_theme_; |
| 54 views::Link* learn_more_; | 54 views::Link* learn_more_; |
| 55 views::Link* close_; | 55 views::Link* close_; |
| 56 | 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(InvertBubbleView); | 57 DISALLOW_COPY_AND_ASSIGN(InvertBubbleView); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 InvertBubbleView::InvertBubbleView(Browser* browser, views::View* anchor_view) | 60 InvertBubbleView::InvertBubbleView(Browser* browser, views::View* anchor_view) |
| 61 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 61 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 62 browser_(browser), | 62 browser_(browser), |
| 63 high_contrast_(NULL), | 63 high_contrast_(NULL), |
| 64 dark_theme_(NULL), | 64 dark_theme_(NULL), |
| 65 learn_more_(NULL), | 65 learn_more_(NULL), |
| 66 close_(NULL) { | 66 close_(NULL) { |
| 67 } | 67 } |
| 68 | 68 |
| 69 InvertBubbleView::~InvertBubbleView() { | 69 InvertBubbleView::~InvertBubbleView() { |
| 70 } | 70 } |
| 71 | 71 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 // Switching to high-contrast mode has a nasty habit of causing Chrome | 120 // Switching to high-contrast mode has a nasty habit of causing Chrome |
| 121 // top-level windows to lose focus, so closing the bubble on deactivate | 121 // top-level windows to lose focus, so closing the bubble on deactivate |
| 122 // makes it disappear before the user has even seen it. This forces the | 122 // makes it disappear before the user has even seen it. This forces the |
| 123 // user to close it explicitly, which should be okay because it affects | 123 // user to close it explicitly, which should be okay because it affects |
| 124 // a small minority of users, and only once. | 124 // a small minority of users, and only once. |
| 125 set_close_on_deactivate(false); | 125 set_close_on_deactivate(false); |
| 126 set_move_with_anchor(true); | 126 set_move_with_anchor(true); |
| 127 } | 127 } |
| 128 | 128 |
| 129 gfx::Rect InvertBubbleView::GetAnchorRect() { | |
| 130 // Set the height to 0 so we display the bubble at the top of the | |
| 131 // anchor rect. | |
| 132 gfx::Rect rect(BubbleDelegateView::GetAnchorRect()); | |
| 133 rect.set_height(0); | |
| 134 return rect; | |
| 135 } | |
| 136 | |
| 137 void InvertBubbleView::LinkClicked(views::Link* source, int event_flags) { | 129 void InvertBubbleView::LinkClicked(views::Link* source, int event_flags) { |
| 138 if (source == high_contrast_) | 130 if (source == high_contrast_) |
| 139 OpenLink(kHighContrastExtensionUrl, event_flags); | 131 OpenLink(kHighContrastExtensionUrl, event_flags); |
| 140 else if (source == dark_theme_) | 132 else if (source == dark_theme_) |
| 141 OpenLink(kDarkThemeSearchUrl, event_flags); | 133 OpenLink(kDarkThemeSearchUrl, event_flags); |
| 142 else if (source == learn_more_) | 134 else if (source == learn_more_) |
| 143 OpenLink(kLearnMoreUrl, event_flags); | 135 OpenLink(kLearnMoreUrl, event_flags); |
| 144 else if (source == close_) | 136 else if (source == close_) |
| 145 GetWidget()->Close(); | 137 GetWidget()->Close(); |
| 146 else | 138 else |
| 147 NOTREACHED(); | 139 NOTREACHED(); |
| 148 } | 140 } |
| 149 | 141 |
| 150 void InvertBubbleView::OpenLink(const std::string& url, int event_flags) { | 142 void InvertBubbleView::OpenLink(const std::string& url, int event_flags) { |
| 151 WindowOpenDisposition disposition = | 143 WindowOpenDisposition disposition = |
| 152 ui::DispositionFromEventFlags(event_flags); | 144 ui::DispositionFromEventFlags(event_flags); |
| 153 content::OpenURLParams params( | 145 content::OpenURLParams params( |
| 154 GURL(url), content::Referrer(), | 146 GURL(url), content::Referrer(), |
| 155 disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition, | 147 disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition, |
| 156 content::PAGE_TRANSITION_LINK, false); | 148 content::PAGE_TRANSITION_LINK, false); |
| 157 browser_->OpenURL(params); | 149 browser_->OpenURL(params); |
| 158 } | 150 } |
| 159 | 151 |
| 160 } // namespace | 152 } // namespace |
| 161 | 153 |
| 162 namespace chrome { | 154 namespace chrome { |
| 163 | 155 |
| 164 void MaybeShowInvertBubbleView(Browser* browser, views::View* anchor_view) { | 156 void MaybeShowInvertBubbleView(BrowserView* browser_view) { |
| 157 Browser* browser = browser_view->browser(); |
| 165 PrefService* pref_service = browser->profile()->GetPrefs(); | 158 PrefService* pref_service = browser->profile()->GetPrefs(); |
| 166 if (gfx::IsInvertedColorScheme() && | 159 views::View* anchor = browser_view->toolbar()->app_menu(); |
| 160 if (gfx::IsInvertedColorScheme() && anchor && anchor->GetWidget() && |
| 167 !pref_service->GetBoolean(prefs::kInvertNotificationShown)) { | 161 !pref_service->GetBoolean(prefs::kInvertNotificationShown)) { |
| 168 pref_service->SetBoolean(prefs::kInvertNotificationShown, true); | 162 pref_service->SetBoolean(prefs::kInvertNotificationShown, true); |
| 169 InvertBubbleView* delegate = new InvertBubbleView(browser, anchor_view); | 163 InvertBubbleView* delegate = new InvertBubbleView(browser, anchor); |
| 170 views::BubbleDelegateView::CreateBubble(delegate); | 164 views::BubbleDelegateView::CreateBubble(delegate); |
| 171 delegate->StartFade(true); | 165 delegate->StartFade(true); |
| 172 } | 166 } |
| 173 } | 167 } |
| 174 | 168 |
| 175 } // namespace chrome | 169 } // namespace chrome |
| OLD | NEW |