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

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

Issue 933893003: Use standard icon/title in global error bubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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
« no previous file with comments | « chrome/browser/ui/views/global_error_bubble_view.h ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/global_error_bubble_view.h" 5 #include "chrome/browser/ui/views/global_error_bubble_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/global_error/global_error.h" 10 #include "chrome/browser/ui/global_error/global_error.h"
11 #include "chrome/browser/ui/global_error/global_error_service.h" 11 #include "chrome/browser/ui/global_error/global_error_service.h"
12 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 12 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
13 #include "chrome/browser/ui/views/elevation_icon_setter.h" 13 #include "chrome/browser/ui/views/elevation_icon_setter.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
16 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" 16 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
19 #include "ui/views/bubble/bubble_frame_view.h"
19 #include "ui/views/controls/button/label_button.h" 20 #include "ui/views/controls/button/label_button.h"
20 #include "ui/views/controls/image_view.h" 21 #include "ui/views/controls/image_view.h"
21 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
22 #include "ui/views/layout/grid_layout.h" 23 #include "ui/views/layout/grid_layout.h"
23 #include "ui/views/layout/layout_constants.h" 24 #include "ui/views/layout/layout_constants.h"
24 25
25 namespace { 26 namespace {
26 27
27 enum { 28 enum {
28 TAG_ACCEPT_BUTTON = 1, 29 TAG_ACCEPT_BUTTON = 1,
29 TAG_CANCEL_BUTTON, 30 TAG_CANCEL_BUTTON,
30 }; 31 };
31 32
32 const int kMaxBubbleViewWidth = 262; 33 const int kMaxBubbleViewWidth = 262;
33 34
34 // The horizontal padding between the title and the icon.
35 const int kTitleHorizontalPadding = 5;
36
37 // The vertical inset of the wrench bubble anchor from the wrench menu button. 35 // The vertical inset of the wrench bubble anchor from the wrench menu button.
38 const int kAnchorVerticalInset = 5; 36 const int kAnchorVerticalInset = 5;
39 37
40 const int kBubblePadding = 6; 38 const int kBubblePadding = 6;
41 39
42 } // namespace 40 } // namespace
43 41
44 // GlobalErrorBubbleViewBase --------------------------------------------------- 42 // GlobalErrorBubbleViewBase ---------------------------------------------------
45 43
46 // static 44 // static
(...skipping 19 matching lines...) Expand all
66 views::BubbleBorder::Arrow arrow, 64 views::BubbleBorder::Arrow arrow,
67 Browser* browser, 65 Browser* browser,
68 const base::WeakPtr<GlobalErrorWithStandardBubble>& error) 66 const base::WeakPtr<GlobalErrorWithStandardBubble>& error)
69 : BubbleDelegateView(anchor_view, arrow), 67 : BubbleDelegateView(anchor_view, arrow),
70 browser_(browser), 68 browser_(browser),
71 error_(error) { 69 error_(error) {
72 // Compensate for built-in vertical padding in the anchor view's image. 70 // Compensate for built-in vertical padding in the anchor view's image.
73 set_anchor_view_insets( 71 set_anchor_view_insets(
74 gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0)); 72 gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0));
75 73
76 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
77 gfx::Image image = error_->GetBubbleViewIcon();
78 CHECK(!image.IsEmpty());
79 scoped_ptr<views::ImageView> image_view(new views::ImageView());
80 image_view->SetImage(image.ToImageSkia());
81
82 base::string16 title_string(error_->GetBubbleViewTitle());
83 scoped_ptr<views::Label> title_label(new views::Label(title_string));
84 title_label->SetMultiLine(true);
85 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
86 title_label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont));
87
88 std::vector<base::string16> message_strings(error_->GetBubbleViewMessages()); 74 std::vector<base::string16> message_strings(error_->GetBubbleViewMessages());
89 std::vector<views::Label*> message_labels; 75 std::vector<views::Label*> message_labels;
90 for (size_t i = 0; i < message_strings.size(); ++i) { 76 for (size_t i = 0; i < message_strings.size(); ++i) {
91 views::Label* message_label = new views::Label(message_strings[i]); 77 views::Label* message_label = new views::Label(message_strings[i]);
92 message_label->SetMultiLine(true); 78 message_label->SetMultiLine(true);
93 message_label->SizeToFit(kMaxBubbleViewWidth); 79 message_label->SizeToFit(kMaxBubbleViewWidth);
94 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 80 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
95 message_labels.push_back(message_label); 81 message_labels.push_back(message_label);
96 } 82 }
97 83
(...skipping 13 matching lines...) Expand all
111 base::string16 cancel_string(error_->GetBubbleViewCancelButtonLabel()); 97 base::string16 cancel_string(error_->GetBubbleViewCancelButtonLabel());
112 scoped_ptr<views::LabelButton> cancel_button; 98 scoped_ptr<views::LabelButton> cancel_button;
113 if (!cancel_string.empty()) { 99 if (!cancel_string.empty()) {
114 cancel_button.reset(new views::LabelButton(this, cancel_string)); 100 cancel_button.reset(new views::LabelButton(this, cancel_string));
115 cancel_button->SetStyle(views::Button::STYLE_BUTTON); 101 cancel_button->SetStyle(views::Button::STYLE_BUTTON);
116 cancel_button->set_tag(TAG_CANCEL_BUTTON); 102 cancel_button->set_tag(TAG_CANCEL_BUTTON);
117 } 103 }
118 104
119 views::GridLayout* layout = new views::GridLayout(this); 105 views::GridLayout* layout = new views::GridLayout(this);
120 SetLayoutManager(layout); 106 SetLayoutManager(layout);
121 layout->SetInsets(kBubblePadding, kBubblePadding,
122 kBubblePadding, kBubblePadding);
123 107
124 // Top row, icon and title. 108 // BubbleFrameView adds enough padding below title, no top padding needed.
109 layout->SetInsets(0, kBubblePadding, kBubblePadding, kBubblePadding);
110
111 // First row, message labels.
125 views::ColumnSet* cs = layout->AddColumnSet(0); 112 views::ColumnSet* cs = layout->AddColumnSet(0);
126 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
127 0, views::GridLayout::USE_PREF, 0, 0);
128 cs->AddPaddingColumn(0, kTitleHorizontalPadding);
129 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 113 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
130 1, views::GridLayout::USE_PREF, 0, 0); 114 1, views::GridLayout::USE_PREF, 0, 0);
131 115
132 // Middle rows, message labels. 116 // Second row, accept and cancel button.
133 cs = layout->AddColumnSet(1); 117 cs = layout->AddColumnSet(1);
134 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
135 1, views::GridLayout::USE_PREF, 0, 0);
136
137 // Bottom row, accept and cancel button.
138 cs = layout->AddColumnSet(2);
139 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); 118 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
140 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 119 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
141 0, views::GridLayout::USE_PREF, 0, 0); 120 0, views::GridLayout::USE_PREF, 0, 0);
142 if (cancel_button.get()) { 121 if (cancel_button.get()) {
143 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 122 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
144 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 123 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
145 0, views::GridLayout::USE_PREF, 0, 0); 124 0, views::GridLayout::USE_PREF, 0, 0);
146 } 125 }
147 126
148 layout->StartRow(1, 0);
149 layout->AddView(image_view.release());
150 layout->AddView(title_label.release());
151 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
152
153 for (size_t i = 0; i < message_labels.size(); ++i) { 127 for (size_t i = 0; i < message_labels.size(); ++i) {
154 layout->StartRow(1, 1); 128 layout->StartRow(1, 0);
155 layout->AddView(message_labels[i]); 129 layout->AddView(message_labels[i]);
156 if (i < message_labels.size() - 1) 130 if (i < message_labels.size() - 1)
157 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 131 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
158 } 132 }
159 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); 133 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing);
160 134
161 layout->StartRow(0, 2); 135 layout->StartRow(0, 1);
162 layout->AddView(accept_button.release()); 136 layout->AddView(accept_button.release());
163 if (cancel_button.get()) 137 if (cancel_button.get())
164 layout->AddView(cancel_button.release()); 138 layout->AddView(cancel_button.release());
165 139
166 // Adjust the message label size in case buttons are too long. 140 // Adjust the message label size in case buttons are too long.
167 for (size_t i = 0; i < message_labels.size(); ++i) 141 for (size_t i = 0; i < message_labels.size(); ++i)
168 message_labels[i]->SizeToFit(layout->GetPreferredSize(this).width()); 142 message_labels[i]->SizeToFit(layout->GetPreferredSize(this).width());
169 143
170 // These bubbles show at times where activation is sporadic (like at startup, 144 // These bubbles show at times where activation is sporadic (like at startup,
171 // or a new window opening). Make sure the bubble doesn't disappear before the 145 // or a new window opening). Make sure the bubble doesn't disappear before the
(...skipping 13 matching lines...) Expand all
185 if (sender->tag() == TAG_ACCEPT_BUTTON) 159 if (sender->tag() == TAG_ACCEPT_BUTTON)
186 error_->BubbleViewAcceptButtonPressed(browser_); 160 error_->BubbleViewAcceptButtonPressed(browser_);
187 else if (sender->tag() == TAG_CANCEL_BUTTON) 161 else if (sender->tag() == TAG_CANCEL_BUTTON)
188 error_->BubbleViewCancelButtonPressed(browser_); 162 error_->BubbleViewCancelButtonPressed(browser_);
189 else 163 else
190 NOTREACHED(); 164 NOTREACHED();
191 } 165 }
192 GetWidget()->Close(); 166 GetWidget()->Close();
193 } 167 }
194 168
169 base::string16 GlobalErrorBubbleView::GetWindowTitle() const {
170 return error_->GetBubbleViewTitle();
171 }
172
173 gfx::ImageSkia GlobalErrorBubbleView::GetWindowIcon() {
174 gfx::Image image = error_->GetBubbleViewIcon();
175 DCHECK(!image.IsEmpty());
176 return *image.ToImageSkia();
177 }
178
179 bool GlobalErrorBubbleView::ShouldShowWindowIcon() const {
180 return true;
181 }
182
195 void GlobalErrorBubbleView::WindowClosing() { 183 void GlobalErrorBubbleView::WindowClosing() {
196 if (error_) 184 if (error_)
197 error_->BubbleViewDidClose(browser_); 185 error_->BubbleViewDidClose(browser_);
198 } 186 }
199 187
200 bool GlobalErrorBubbleView::ShouldShowCloseButton() const { 188 bool GlobalErrorBubbleView::ShouldShowCloseButton() const {
201 return error_ && error_->ShouldShowCloseButton(); 189 return error_ && error_->ShouldShowCloseButton();
202 } 190 }
203 191
204 void GlobalErrorBubbleView::CloseBubbleView() { 192 void GlobalErrorBubbleView::CloseBubbleView() {
205 GetWidget()->Close(); 193 GetWidget()->Close();
206 } 194 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/global_error_bubble_view.h ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698