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/exclusive_access_bubble_views.h" | 5 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | |
7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_split.h" | |
8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 13 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
12 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 14 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
13 #include "chrome/browser/ui/views/exclusive_access_bubble_views_context.h" | 15 #include "chrome/browser/ui/views/exclusive_access_bubble_views_context.h" |
14 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 16 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
15 #include "chrome/browser/ui/views/frame/top_container_view.h" | 17 #include "chrome/browser/ui/views/frame/top_container_view.h" |
16 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
17 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 deny_button_->SetFocusable(false); | 76 deny_button_->SetFocusable(false); |
75 AddChildView(deny_button_); | 77 AddChildView(deny_button_); |
76 | 78 |
77 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 79 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
78 between_button_spacing)); | 80 between_button_spacing)); |
79 } | 81 } |
80 | 82 |
81 ButtonView::~ButtonView() { | 83 ButtonView::~ButtonView() { |
82 } | 84 } |
83 | 85 |
86 // Class containing the exit instruction text. Contains fancy styling on the | |
87 // keyboard key (not just a simple label). | |
88 class InstructionView : public views::View { | |
89 public: | |
90 // Creates an InstructionView with specific text. |text| may contain a single | |
91 // segment delimited by a pair of pipes ('|'); this segment will be displayed | |
92 // as a keyboard key. e.g., "Press |Esc| to exit" will have "Esc" rendered as | |
93 // a key. | |
94 InstructionView(const base::string16& text, | |
95 const gfx::FontList& font_list, | |
96 SkColor foreground_color, | |
97 SkColor background_color); | |
98 | |
99 private: | |
100 DISALLOW_COPY_AND_ASSIGN(InstructionView); | |
101 }; | |
102 | |
103 InstructionView::InstructionView(const base::string16& text, | |
104 const gfx::FontList& font_list, | |
105 SkColor foreground_color, | |
106 SkColor background_color) { | |
107 // Spacing around the escape key name. | |
108 const int kKeyNameMarginHorizPx = 7; | |
109 const int kKeyNameBorderPx = 2; | |
110 const int kKeyNameCornerRadius = 2; | |
111 const int kKeyNamePaddingPx = 7; | |
Evan Stade
2015/11/12 01:27:37
imo these are c-style variable declarations (every
Matt Giuca
2015/11/12 03:22:10
Done.
(Personally, I prefer having it at the top
| |
112 | |
113 // Parse |text|, looking for pipe-delimited segment. | |
114 std::vector<base::string16> segments = | |
115 base::SplitString(text, base::ASCIIToUTF16("|"), base::TRIM_WHITESPACE, | |
116 base::SPLIT_WANT_ALL); | |
117 // Expect 1 or 3 pieces (either no pipe-delimited segments, or one). | |
118 DCHECK(segments.size() == 1 || segments.size() == 3); | |
119 | |
120 bool has_key = segments.size() == 3; | |
msw
2015/11/12 01:19:49
nit: inline in the if statement below, or move dow
Matt Giuca
2015/11/12 03:22:10
Done.
| |
121 // The |between_child_spacing| is the horizontal margin of the key name. | |
122 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, | |
123 0, 0, kKeyNameMarginHorizPx); | |
124 SetLayoutManager(layout); | |
125 | |
126 views::Label* before_key = new views::Label(segments[0], font_list); | |
127 before_key->SetEnabledColor(foreground_color); | |
128 before_key->SetBackgroundColor(background_color); | |
129 AddChildView(before_key); | |
130 | |
131 if (has_key) { | |
132 base::string16 key = base::i18n::ToUpper(segments[1]); | |
133 views::Label* key_name_label = new views::Label(key, font_list); | |
134 key_name_label->SetEnabledColor(foreground_color); | |
135 key_name_label->SetBackgroundColor(background_color); | |
136 | |
137 views::View* key_name = new views::View; | |
138 views::BoxLayout* key_name_layout = new views::BoxLayout( | |
139 views::BoxLayout::kHorizontal, kKeyNamePaddingPx, kKeyNamePaddingPx, 0); | |
140 key_name->SetLayoutManager(key_name_layout); | |
141 key_name->AddChildView(key_name_label); | |
142 // The key name has a border around it. | |
143 scoped_ptr<views::Border> border(views::Border::CreateRoundedRectBorder( | |
144 kKeyNameBorderPx, kKeyNameCornerRadius, foreground_color)); | |
145 key_name->SetBorder(border.Pass()); | |
146 AddChildView(key_name); | |
147 | |
148 views::Label* after_key = new views::Label(segments[2], font_list); | |
149 after_key->SetEnabledColor(foreground_color); | |
150 after_key->SetBackgroundColor(background_color); | |
151 AddChildView(after_key); | |
152 } | |
153 } | |
154 | |
84 } // namespace | 155 } // namespace |
85 | 156 |
86 class ExclusiveAccessBubbleViews::ExclusiveAccessView | 157 class ExclusiveAccessBubbleViews::ExclusiveAccessView |
87 : public views::View, | 158 : public views::View, |
88 public views::ButtonListener, | 159 public views::ButtonListener, |
89 public views::LinkListener { | 160 public views::LinkListener { |
90 public: | 161 public: |
91 ExclusiveAccessView(ExclusiveAccessBubbleViews* bubble, | 162 ExclusiveAccessView(ExclusiveAccessBubbleViews* bubble, |
92 const base::string16& accelerator, | 163 const base::string16& accelerator, |
93 const GURL& url, | 164 const GURL& url, |
(...skipping 14 matching lines...) Expand all Loading... | |
108 // Clickable hint text for exiting fullscreen mode. (Non-simplified mode | 179 // Clickable hint text for exiting fullscreen mode. (Non-simplified mode |
109 // only.) | 180 // only.) |
110 views::Link* link_; | 181 views::Link* link_; |
111 // Informational label: 'www.foo.com has gone fullscreen'. (Non-simplified | 182 // Informational label: 'www.foo.com has gone fullscreen'. (Non-simplified |
112 // mode only.) | 183 // mode only.) |
113 views::Label* message_label_; | 184 views::Label* message_label_; |
114 // Clickable buttons to exit fullscreen. (Non-simplified mode only.) | 185 // Clickable buttons to exit fullscreen. (Non-simplified mode only.) |
115 ButtonView* button_view_; | 186 ButtonView* button_view_; |
116 // Instruction for exiting fullscreen / mouse lock. Only present if there is | 187 // Instruction for exiting fullscreen / mouse lock. Only present if there is |
117 // no link or button (always present in simplified mode). | 188 // no link or button (always present in simplified mode). |
118 views::Label* exit_instruction_; | 189 InstructionView* exit_instruction_; |
119 const base::string16 browser_fullscreen_exit_accelerator_; | 190 const base::string16 browser_fullscreen_exit_accelerator_; |
120 | 191 |
121 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessView); | 192 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessView); |
122 }; | 193 }; |
123 | 194 |
124 ExclusiveAccessBubbleViews::ExclusiveAccessView::ExclusiveAccessView( | 195 ExclusiveAccessBubbleViews::ExclusiveAccessView::ExclusiveAccessView( |
125 ExclusiveAccessBubbleViews* bubble, | 196 ExclusiveAccessBubbleViews* bubble, |
126 const base::string16& accelerator, | 197 const base::string16& accelerator, |
127 const GURL& url, | 198 const GURL& url, |
128 ExclusiveAccessBubbleType bubble_type) | 199 ExclusiveAccessBubbleType bubble_type) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 const gfx::FontList& medium_font_list = | 233 const gfx::FontList& medium_font_list = |
163 rb.GetFontList(ui::ResourceBundle::MediumFont); | 234 rb.GetFontList(ui::ResourceBundle::MediumFont); |
164 | 235 |
165 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) { | 236 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) { |
166 message_label_ = new views::Label(base::string16(), medium_font_list); | 237 message_label_ = new views::Label(base::string16(), medium_font_list); |
167 message_label_->SetEnabledColor(foreground_color); | 238 message_label_->SetEnabledColor(foreground_color); |
168 message_label_->SetBackgroundColor(background_color); | 239 message_label_->SetBackgroundColor(background_color); |
169 } | 240 } |
170 | 241 |
171 exit_instruction_ = | 242 exit_instruction_ = |
172 new views::Label(bubble_->GetInstructionText(), medium_font_list); | 243 new InstructionView(bubble_->GetInstructionText(), medium_font_list, |
173 exit_instruction_->SetEnabledColor(foreground_color); | 244 foreground_color, background_color); |
174 exit_instruction_->SetBackgroundColor(background_color); | |
175 | 245 |
176 link_ = new views::Link(); | 246 link_ = new views::Link(); |
177 link_->SetFocusable(false); | 247 link_->SetFocusable(false); |
178 #if defined(OS_CHROMEOS) | 248 #if defined(OS_CHROMEOS) |
179 // On CrOS, the link text doesn't change, since it doesn't show the shortcut. | 249 // On CrOS, the link text doesn't change, since it doesn't show the shortcut. |
180 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE)); | 250 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE)); |
181 #endif | 251 #endif |
182 link_->set_listener(this); | 252 link_->set_listener(this); |
183 link_->SetFontList(medium_font_list); | 253 link_->SetFontList(medium_font_list); |
184 link_->SetPressedColor(foreground_color); | 254 link_->SetPressedColor(foreground_color); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 const content::NotificationDetails& details) { | 616 const content::NotificationDetails& details) { |
547 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 617 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
548 UpdateForImmersiveState(); | 618 UpdateForImmersiveState(); |
549 } | 619 } |
550 | 620 |
551 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( | 621 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( |
552 views::Widget* widget, | 622 views::Widget* widget, |
553 bool visible) { | 623 bool visible) { |
554 UpdateMouseWatcher(); | 624 UpdateMouseWatcher(); |
555 } | 625 } |
OLD | NEW |