Chromium Code Reviews| Index: chrome/browser/ui/views/exclusive_access_bubble_views.cc |
| diff --git a/chrome/browser/ui/views/exclusive_access_bubble_views.cc b/chrome/browser/ui/views/exclusive_access_bubble_views.cc |
| index 3bebd07b47585b5083de16085b434a59d3935273..4623dead17773bbc85adc6cf47faddd71b3a5bfb 100644 |
| --- a/chrome/browser/ui/views/exclusive_access_bubble_views.cc |
| +++ b/chrome/browser/ui/views/exclusive_access_bubble_views.cc |
| @@ -4,7 +4,9 @@ |
| #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
| +#include "base/i18n/case_conversion.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| @@ -44,6 +46,11 @@ namespace { |
| // Space between the site info label and the buttons / link. |
| const int kMiddlePaddingPx = 30; |
| +// Spacing around the escape key name. |
| +const int kKeyNameMarginHorizPx = 7; |
| +const int kKeyNameMarginVertPx = 0; |
| +const int kKeyNamePaddingPx = 7; |
| + |
| // Opacity of the background (out of 255). Only used with |
| // IsSimplifiedFullscreenUIEnabled. |
| const unsigned char kBackgroundOpacity = 180; |
| @@ -85,6 +92,73 @@ ButtonView::ButtonView(views::ButtonListener* listener, |
| ButtonView::~ButtonView() { |
| } |
| +// Class containing the exit instruction text. Contains fancy styling on the |
| +// keyboard key (not just a simple label). |
| +class InstructionView : public views::View { |
| + public: |
| + // Creates an InstructionView with specific text. |text| may contain a single |
| + // segment delimited by a pair of pipes ('|'); this segment will be displayed |
| + // as a keyboard key. e.g., "Press |Esc| to exit" will have "Esc" rendered as |
| + // a key. |
| + InstructionView(const base::string16& text, |
| + const gfx::FontList& font_list, |
| + SkColor foreground_color, |
| + 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
|
| + |
| + private: |
| + 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.
|
| + views::View* key_name_; |
| + 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.
|
| +}; |
| + |
| +InstructionView::InstructionView(const base::string16& text, |
| + const gfx::FontList& font_list, |
| + SkColor foreground_color, |
| + SkColor background_color) |
| + : before_key_(nullptr), key_name_(nullptr), after_key_(nullptr) { |
| + // Parse |text|, looking for pipe-delimited segment. |
| + 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.
|
| + base::SplitString(text, base::ASCIIToUTF16("|"), base::TRIM_WHITESPACE, |
| + base::SPLIT_WANT_ALL); |
| + // Expect 1 or 3 pieces (either no pipe-delimited segments, or one). |
| + DCHECK(segments.size() == 1 || segments.size() == 3); |
| + |
| + bool has_key = segments.size() == 3; |
| + 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
|
| + views::BoxLayout* layout = new views::BoxLayout( |
| + views::BoxLayout::kHorizontal, 0, margin_vert, kKeyNameMarginHorizPx); |
| + SetLayoutManager(layout); |
| + layout->set_collapse_when_hidden(true); |
| + |
| + before_key_ = new views::Label(segments[0], font_list); |
| + before_key_->SetEnabledColor(foreground_color); |
| + before_key_->SetBackgroundColor(background_color); |
| + AddChildView(before_key_); |
| + |
| + if (has_key) { |
| + 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
|
| + views::Label* key_name_label = new views::Label(key, font_list); |
| + key_name_label->SetEnabledColor(foreground_color); |
| + key_name_label->SetBackgroundColor(background_color); |
| + |
| + key_name_ = new views::View; |
| + views::BoxLayout* key_name_layout = new views::BoxLayout( |
| + views::BoxLayout::kHorizontal, kKeyNamePaddingPx, kKeyNamePaddingPx, 0); |
| + 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.
|
| + key_name_->AddChildView(key_name_label); |
| + // The key name has a border around it. |
| + scoped_ptr<views::Border> border( |
| + 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
|
| + key_name_->SetBorder(border.Pass()); |
| + AddChildView(key_name_); |
| + |
| + after_key_ = new views::Label(segments[2], font_list); |
| + after_key_->SetEnabledColor(foreground_color); |
| + after_key_->SetBackgroundColor(background_color); |
| + AddChildView(after_key_); |
| + } |
| +} |
| + |
| gfx::Size ButtonView::GetPreferredSize() const { |
| return visible() ? views::View::GetPreferredSize() : gfx::Size(); |
| } |
| @@ -123,7 +197,7 @@ class ExclusiveAccessBubbleViews::ExclusiveAccessView |
| ButtonView* button_view_; |
| // Instruction for exiting fullscreen / mouse lock. Only present if there is |
| // no link or button (always present in simplified mode). |
| - views::Label* exit_instruction_; |
| + InstructionView* exit_instruction_; |
| const base::string16 browser_fullscreen_exit_accelerator_; |
| DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessView); |
| @@ -177,11 +251,8 @@ ExclusiveAccessBubbleViews::ExclusiveAccessView::ExclusiveAccessView( |
| } |
| exit_instruction_ = |
| - new views::Label(bubble_->GetInstructionText(), medium_font_list); |
| - exit_instruction_->set_collapse_when_hidden(true); |
| - |
| - exit_instruction_->SetEnabledColor(foreground_color); |
| - exit_instruction_->SetBackgroundColor(background_color); |
| + new InstructionView(bubble_->GetInstructionText(), medium_font_list, |
| + foreground_color, background_color); |
| link_ = new views::Link(); |
| link_->set_collapse_when_hidden(true); |