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

Side by Side Diff: chrome/browser/ui/views/exclusive_access_bubble_views.cc

Issue 1421813005: Fullscreen bubble: Draw a white box around "ESC" in "Press ESC to exit". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@border-roundedrect
Patch Set: Created 5 years, 1 month 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
OLDNEW
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 19 matching lines...) Expand all
37 #include "ui/base/l10n/l10n_util_win.h" 39 #include "ui/base/l10n/l10n_util_win.h"
38 #endif 40 #endif
39 41
40 // ExclusiveAccessView --------------------------------------------------------- 42 // ExclusiveAccessView ---------------------------------------------------------
41 43
42 namespace { 44 namespace {
43 45
44 // Space between the site info label and the buttons / link. 46 // Space between the site info label and the buttons / link.
45 const int kMiddlePaddingPx = 30; 47 const int kMiddlePaddingPx = 30;
46 48
49 // Spacing around the escape key name.
50 const int kKeyNameMarginHorizPx = 7;
51 const int kKeyNameMarginVertPx = 0;
52 const int kKeyNamePaddingPx = 7;
53
47 // Opacity of the background (out of 255). Only used with 54 // Opacity of the background (out of 255). Only used with
48 // IsSimplifiedFullscreenUIEnabled. 55 // IsSimplifiedFullscreenUIEnabled.
49 const unsigned char kBackgroundOpacity = 180; 56 const unsigned char kBackgroundOpacity = 180;
50 57
51 class ButtonView : public views::View { 58 class ButtonView : public views::View {
52 public: 59 public:
53 ButtonView(views::ButtonListener* listener, int between_button_spacing); 60 ButtonView(views::ButtonListener* listener, int between_button_spacing);
54 ~ButtonView() override; 61 ~ButtonView() override;
55 62
56 // Returns an empty size when the view is not visible. 63 // Returns an empty size when the view is not visible.
(...skipping 21 matching lines...) Expand all
78 deny_button_->SetFocusable(false); 85 deny_button_->SetFocusable(false);
79 AddChildView(deny_button_); 86 AddChildView(deny_button_);
80 87
81 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 88 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0,
82 between_button_spacing)); 89 between_button_spacing));
83 } 90 }
84 91
85 ButtonView::~ButtonView() { 92 ButtonView::~ButtonView() {
86 } 93 }
87 94
95 // Class containing the exit instruction text. Contains fancy styling on the
96 // keyboard key (not just a simple label).
97 class InstructionView : public views::View {
98 public:
99 // Creates an InstructionView with specific text. |text| may contain a single
100 // segment delimited by a pair of pipes ('|'); this segment will be displayed
101 // as a keyboard key. e.g., "Press |Esc| to exit" will have "Esc" rendered as
102 // a key.
103 InstructionView(const base::string16& text,
104 const gfx::FontList& font_list,
105 SkColor foreground_color,
106 SkColor background_color);
Evan Stade 2015/10/29 00:49:53 I don't think you need to pass background_color, j
Matt Giuca 2015/11/09 06:35:12 Not sure what the problem is here or what that cha
107
108 private:
109 views::Label* before_key_;
Evan Stade 2015/10/29 00:49:53 are these members necessary? you only use them in
Matt Giuca 2015/11/09 06:35:12 Done.
110 views::View* key_name_;
111 views::Label* after_key_;
Evan Stade 2015/10/29 00:49:53 DISALLOW_COPY_AND_ASSIGN
Matt Giuca 2015/11/09 06:35:12 Done.
112 };
113
114 InstructionView::InstructionView(const base::string16& text,
115 const gfx::FontList& font_list,
116 SkColor foreground_color,
117 SkColor background_color)
118 : before_key_(nullptr), key_name_(nullptr), after_key_(nullptr) {
119 // Parse |text|, looking for pipe-delimited segment.
120 std::vector<base::string16> segments =
Evan Stade 2015/11/04 00:37:20 technically the style guide says not to call virtu
Matt Giuca 2015/11/09 06:35:12 Which virtual method am I calling? I can't find an
Evan Stade 2015/11/09 18:51:24 ah, very true, I guess I was thinking AddChildView
Matt Giuca 2015/11/12 01:03:46 Acknowledged.
121 base::SplitString(text, base::ASCIIToUTF16("|"), base::TRIM_WHITESPACE,
122 base::SPLIT_WANT_ALL);
123 // Expect 1 or 3 pieces (either no pipe-delimited segments, or one).
124 DCHECK(segments.size() == 1 || segments.size() == 3);
125
126 bool has_key = segments.size() == 3;
127 int margin_vert = has_key ? kKeyNameMarginVertPx : 0;
msw 2015/10/29 17:50:02 kKeyNameMarginVertPx is also zero, perhaps |margin
Matt Giuca 2015/11/09 06:35:12 I think it makes sense to keep this (otherwise it
msw 2015/11/09 18:28:47 The 'configurable horizontal margin' you mention i
Matt Giuca 2015/11/12 01:03:46 The naming is correct, from thinking about it as C
128 views::BoxLayout* layout = new views::BoxLayout(
129 views::BoxLayout::kHorizontal, 0, margin_vert, kKeyNameMarginHorizPx);
130 SetLayoutManager(layout);
131 layout->set_collapse_when_hidden(true);
132
133 before_key_ = new views::Label(segments[0], font_list);
134 before_key_->SetEnabledColor(foreground_color);
135 before_key_->SetBackgroundColor(background_color);
136 AddChildView(before_key_);
137
138 if (has_key) {
139 base::string16 key = base::i18n::ToUpper(segments[1]);
Evan Stade 2015/10/29 00:49:53 why is this ToUpper instead of making the source s
Evan Stade 2015/10/29 00:58:36 Talked to Sebastien, he says to use "Esc" (he does
Matt Giuca 2015/10/29 22:04:24 Separation of presentation from content (as you wo
140 views::Label* key_name_label = new views::Label(key, font_list);
141 key_name_label->SetEnabledColor(foreground_color);
142 key_name_label->SetBackgroundColor(background_color);
143
144 key_name_ = new views::View;
145 views::BoxLayout* key_name_layout = new views::BoxLayout(
146 views::BoxLayout::kHorizontal, kKeyNamePaddingPx, kKeyNamePaddingPx, 0);
147 key_name_->SetLayoutManager(key_name_layout);
msw 2015/10/29 17:50:02 Why do you need a separate layout manager for the
Matt Giuca 2015/11/09 06:35:12 Essentially what I want (in HTML/CSS terms) is for
msw 2015/11/09 18:28:47 Views have insets, which amount to padding, but th
Matt Giuca 2015/11/12 01:03:45 Acknowledged.
148 key_name_->AddChildView(key_name_label);
149 // The key name has a border around it.
150 scoped_ptr<views::Border> border(
151 views::Border::CreateRoundedRectBorder(2, 2, foreground_color));
Evan Stade 2015/10/29 00:49:53 Interesting how different this is to a very simila
Matt Giuca 2015/10/29 06:41:01 Do you think you could use CreateRoundedRectBorder
Evan Stade 2015/10/29 18:36:41 I think I could use it, but it doesn't buy much (C
Evan Stade 2015/10/29 21:11:30 Actually I take it back, I couldn't use this borde
Evan Stade 2015/11/04 00:37:20 are you sure this thickness matches the spec? I th
Matt Giuca 2015/11/09 06:35:12 Maybe... I tried with 1px and 2px and 1px just loo
Evan Stade 2015/11/09 18:51:25 see my comment in the other CL (which imo should b
Matt Giuca 2015/11/12 01:03:46 OK I've fixed the underlying issue in the other CL
Evan Stade 2015/11/12 01:27:37 I don't think it does match the mocks visually. Th
152 key_name_->SetBorder(border.Pass());
153 AddChildView(key_name_);
154
155 after_key_ = new views::Label(segments[2], font_list);
156 after_key_->SetEnabledColor(foreground_color);
157 after_key_->SetBackgroundColor(background_color);
158 AddChildView(after_key_);
159 }
160 }
161
88 gfx::Size ButtonView::GetPreferredSize() const { 162 gfx::Size ButtonView::GetPreferredSize() const {
89 return visible() ? views::View::GetPreferredSize() : gfx::Size(); 163 return visible() ? views::View::GetPreferredSize() : gfx::Size();
90 } 164 }
91 165
92 } // namespace 166 } // namespace
93 167
94 class ExclusiveAccessBubbleViews::ExclusiveAccessView 168 class ExclusiveAccessBubbleViews::ExclusiveAccessView
95 : public views::View, 169 : public views::View,
96 public views::ButtonListener, 170 public views::ButtonListener,
97 public views::LinkListener { 171 public views::LinkListener {
(...skipping 18 matching lines...) Expand all
116 // Clickable hint text for exiting fullscreen mode. (Non-simplified mode 190 // Clickable hint text for exiting fullscreen mode. (Non-simplified mode
117 // only.) 191 // only.)
118 views::Link* link_; 192 views::Link* link_;
119 // Informational label: 'www.foo.com has gone fullscreen'. (Non-simplified 193 // Informational label: 'www.foo.com has gone fullscreen'. (Non-simplified
120 // mode only.) 194 // mode only.)
121 views::Label* message_label_; 195 views::Label* message_label_;
122 // Clickable buttons to exit fullscreen. (Non-simplified mode only.) 196 // Clickable buttons to exit fullscreen. (Non-simplified mode only.)
123 ButtonView* button_view_; 197 ButtonView* button_view_;
124 // Instruction for exiting fullscreen / mouse lock. Only present if there is 198 // Instruction for exiting fullscreen / mouse lock. Only present if there is
125 // no link or button (always present in simplified mode). 199 // no link or button (always present in simplified mode).
126 views::Label* exit_instruction_; 200 InstructionView* exit_instruction_;
127 const base::string16 browser_fullscreen_exit_accelerator_; 201 const base::string16 browser_fullscreen_exit_accelerator_;
128 202
129 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessView); 203 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessView);
130 }; 204 };
131 205
132 ExclusiveAccessBubbleViews::ExclusiveAccessView::ExclusiveAccessView( 206 ExclusiveAccessBubbleViews::ExclusiveAccessView::ExclusiveAccessView(
133 ExclusiveAccessBubbleViews* bubble, 207 ExclusiveAccessBubbleViews* bubble,
134 const base::string16& accelerator, 208 const base::string16& accelerator,
135 const GURL& url, 209 const GURL& url,
136 ExclusiveAccessBubbleType bubble_type) 210 ExclusiveAccessBubbleType bubble_type)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 const gfx::FontList& medium_font_list = 244 const gfx::FontList& medium_font_list =
171 rb.GetFontList(ui::ResourceBundle::MediumFont); 245 rb.GetFontList(ui::ResourceBundle::MediumFont);
172 246
173 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) { 247 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) {
174 message_label_ = new views::Label(base::string16(), medium_font_list); 248 message_label_ = new views::Label(base::string16(), medium_font_list);
175 message_label_->SetEnabledColor(foreground_color); 249 message_label_->SetEnabledColor(foreground_color);
176 message_label_->SetBackgroundColor(background_color); 250 message_label_->SetBackgroundColor(background_color);
177 } 251 }
178 252
179 exit_instruction_ = 253 exit_instruction_ =
180 new views::Label(bubble_->GetInstructionText(), medium_font_list); 254 new InstructionView(bubble_->GetInstructionText(), medium_font_list,
181 exit_instruction_->set_collapse_when_hidden(true); 255 foreground_color, background_color);
182
183 exit_instruction_->SetEnabledColor(foreground_color);
184 exit_instruction_->SetBackgroundColor(background_color);
185 256
186 link_ = new views::Link(); 257 link_ = new views::Link();
187 link_->set_collapse_when_hidden(true); 258 link_->set_collapse_when_hidden(true);
188 link_->SetFocusable(false); 259 link_->SetFocusable(false);
189 #if defined(OS_CHROMEOS) 260 #if defined(OS_CHROMEOS)
190 // On CrOS, the link text doesn't change, since it doesn't show the shortcut. 261 // On CrOS, the link text doesn't change, since it doesn't show the shortcut.
191 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE)); 262 link_->SetText(l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_MODE));
192 #endif 263 #endif
193 link_->set_listener(this); 264 link_->set_listener(this);
194 link_->SetFontList(medium_font_list); 265 link_->SetFontList(medium_font_list);
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 const content::NotificationDetails& details) { 646 const content::NotificationDetails& details) {
576 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); 647 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type);
577 UpdateForImmersiveState(); 648 UpdateForImmersiveState();
578 } 649 }
579 650
580 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( 651 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged(
581 views::Widget* widget, 652 views::Widget* widget,
582 bool visible) { 653 bool visible) {
583 UpdateMouseWatcher(); 654 UpdateMouseWatcher();
584 } 655 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698