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

Side by Side Diff: ui/views/bubble/bubble_frame_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
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 "ui/views/bubble/bubble_frame_view.h" 5 #include "ui/views/bubble/bubble_frame_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/base/hit_test.h" 9 #include "ui/base/hit_test.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/path.h" 11 #include "ui/gfx/path.h"
12 #include "ui/gfx/screen.h" 12 #include "ui/gfx/screen.h"
13 #include "ui/gfx/skia_util.h" 13 #include "ui/gfx/skia_util.h"
14 #include "ui/native_theme/native_theme.h" 14 #include "ui/native_theme/native_theme.h"
15 #include "ui/resources/grit/ui_resources.h" 15 #include "ui/resources/grit/ui_resources.h"
16 #include "ui/views/bubble/bubble_border.h" 16 #include "ui/views/bubble/bubble_border.h"
17 #include "ui/views/controls/button/label_button.h" 17 #include "ui/views/controls/button/label_button.h"
18 #include "ui/views/controls/image_view.h"
18 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
19 #include "ui/views/widget/widget_delegate.h" 20 #include "ui/views/widget/widget_delegate.h"
20 #include "ui/views/window/client_view.h" 21 #include "ui/views/window/client_view.h"
21 22
22 namespace { 23 namespace {
23 24
24 // Insets for the title bar views in pixels. 25 // Insets for the title bar views in pixels.
25 const int kTitleTopInset = 12; 26 const int kTitleTopInset = 12;
26 const int kTitleLeftInset = 19; 27 const int kTitleLeftInset = 19;
27 const int kTitleBottomInset = 12; 28 const int kTitleBottomInset = 12;
(...skipping 25 matching lines...) Expand all
53 } // namespace 54 } // namespace
54 55
55 namespace views { 56 namespace views {
56 57
57 // static 58 // static
58 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView"; 59 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView";
59 60
60 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins) 61 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins)
61 : bubble_border_(NULL), 62 : bubble_border_(NULL),
62 content_margins_(content_margins), 63 content_margins_(content_margins),
64 title_icon_(NULL),
63 title_(NULL), 65 title_(NULL),
64 close_(NULL), 66 close_(NULL),
65 titlebar_extra_view_(NULL) { 67 titlebar_extra_view_(NULL) {
66 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 68 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
69 title_icon_ = new views::ImageView();
70 AddChildView(title_icon_);
71
67 title_ = new Label(base::string16(), 72 title_ = new Label(base::string16(),
68 rb.GetFontList(ui::ResourceBundle::MediumFont)); 73 rb.GetFontList(ui::ResourceBundle::MediumFont));
69 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 74 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
70 AddChildView(title_); 75 AddChildView(title_);
71 76
72 close_ = CreateCloseButton(this); 77 close_ = CreateCloseButton(this);
73 close_->SetVisible(false); 78 close_->SetVisible(false);
74 AddChildView(close_); 79 AddChildView(close_);
75 } 80 }
76 81
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 162 }
158 } 163 }
159 164
160 void BubbleFrameView::ResetWindowControls() { 165 void BubbleFrameView::ResetWindowControls() {
161 close_->SetVisible(GetWidget()->widget_delegate()->ShouldShowCloseButton()); 166 close_->SetVisible(GetWidget()->widget_delegate()->ShouldShowCloseButton());
162 } 167 }
163 168
164 void BubbleFrameView::UpdateWindowIcon() {} 169 void BubbleFrameView::UpdateWindowIcon() {}
165 170
166 void BubbleFrameView::UpdateWindowTitle() { 171 void BubbleFrameView::UpdateWindowTitle() {
172 gfx::ImageSkia image;
173 if (GetWidget()->widget_delegate()->ShouldShowWindowTitleIcon())
174 image = GetWidget()->widget_delegate()->GetWindowTitleIcon();
175 title_icon_->SetImage(&image);
176
167 title_->SetText(GetWidget()->widget_delegate()->ShouldShowWindowTitle() ? 177 title_->SetText(GetWidget()->widget_delegate()->ShouldShowWindowTitle() ?
168 GetWidget()->widget_delegate()->GetWindowTitle() : base::string16()); 178 GetWidget()->widget_delegate()->GetWindowTitle() : base::string16());
169 // Update the close button visibility too, otherwise it's not intialized. 179 // Update the close button visibility too, otherwise it's not intialized.
170 ResetWindowControls(); 180 ResetWindowControls();
171 } 181 }
172 182
173 void BubbleFrameView::SizeConstraintsChanged() {} 183 void BubbleFrameView::SizeConstraintsChanged() {}
174 184
175 void BubbleFrameView::SetTitleFontList(const gfx::FontList& font_list) { 185 void BubbleFrameView::SetTitleFontList(const gfx::FontList& font_list) {
176 title_->SetFontList(font_list); 186 title_->SetFontList(font_list);
(...skipping 19 matching lines...) Expand all
196 void BubbleFrameView::Layout() { 206 void BubbleFrameView::Layout() {
197 gfx::Rect bounds(GetContentsBounds()); 207 gfx::Rect bounds(GetContentsBounds());
198 bounds.Inset(GetTitleInsets()); 208 bounds.Inset(GetTitleInsets());
199 if (bounds.IsEmpty()) 209 if (bounds.IsEmpty())
200 return; 210 return;
201 211
202 // The close button top inset is actually smaller than the title top inset. 212 // The close button top inset is actually smaller than the title top inset.
203 close_->SetPosition(gfx::Point(bounds.right() - close_->width(), 213 close_->SetPosition(gfx::Point(bounds.right() - close_->width(),
204 bounds.y() - 5)); 214 bounds.y() - 5));
205 215
206 gfx::Size title_size(title_->GetPreferredSize()); 216 gfx::Size title_icon_size(title_icon_->GetPreferredSize());
207 const int title_width = std::max(0, close_->x() - bounds.x()); 217 gfx::Size title_label_size(title_->GetPreferredSize());
208 title_size.SetToMin(gfx::Size(title_width, title_size.height())); 218 const int title_height = std::max(title_icon_size.height(),
209 bounds.set_size(title_size); 219 title_label_size.height());
210 title_->SetBoundsRect(bounds); 220
221 const int title_icon_width = std::max(0, close_->x() - bounds.x());
222 title_icon_size.SetToMin(gfx::Size(title_icon_width, title_height));
223 gfx::Rect title_icon_bounds(
224 bounds.x(),
225 bounds.y() + (title_height - title_icon_size.height()) / 2,
226 title_icon_size.width(),
227 title_icon_size.height());
228 title_icon_->SetBoundsRect(title_icon_bounds);
229
230 const int title_label_x = title_icon_->bounds().right() + 5;
231 const int title_width = std::max(0, close_->x() - title_label_x);
232 title_label_size.SetToMin(gfx::Size(title_width, title_label_size.height()));
233 gfx::Rect title_label_bounds(
234 title_label_x,
235 bounds.y() + (title_height - title_label_size.height()) / 2,
236 title_label_size.width(),
237 title_label_size.height());
238 title_->SetBoundsRect(title_label_bounds);
211 239
212 if (titlebar_extra_view_) { 240 if (titlebar_extra_view_) {
213 const int extra_width = close_->x() - title_->bounds().right(); 241 const int extra_width = close_->x() - title_->bounds().right();
214 gfx::Size size = titlebar_extra_view_->GetPreferredSize(); 242 gfx::Size size = titlebar_extra_view_->GetPreferredSize();
215 size.SetToMin(gfx::Size(std::max(0, extra_width), size.height())); 243 size.SetToMin(gfx::Size(std::max(0, extra_width), size.height()));
216 gfx::Rect titlebar_extra_view_bounds( 244 gfx::Rect titlebar_extra_view_bounds(
217 close_->x() - size.width(), 245 close_->x() - size.width(),
218 bounds.y(), 246 bounds.y(),
219 size.width(), 247 size.width(),
220 bounds.height()); 248 bounds.height());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 bubble_border_->set_arrow_offset( 392 bubble_border_->set_arrow_offset(
365 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust); 393 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust);
366 if (offscreen_adjust) 394 if (offscreen_adjust)
367 SchedulePaint(); 395 SchedulePaint();
368 } 396 }
369 397
370 gfx::Size BubbleFrameView::GetSizeForClientSize( 398 gfx::Size BubbleFrameView::GetSizeForClientSize(
371 const gfx::Size& client_size) const { 399 const gfx::Size& client_size) const {
372 // Accommodate the width of the title bar elements. 400 // Accommodate the width of the title bar elements.
373 int title_bar_width = GetInsets().width() + border()->GetInsets().width(); 401 int title_bar_width = GetInsets().width() + border()->GetInsets().width();
402 gfx::Size title_icon_size = title_icon_->GetPreferredSize();
403 if (title_icon_size.width() > 0 || !title_->text().empty()) {
404 title_bar_width += kTitleLeftInset;
405 }
406 if (title_icon_size.width() > 0) {
407 title_bar_width += title_icon_size.width() + 5;
408 }
374 if (!title_->text().empty()) 409 if (!title_->text().empty())
375 title_bar_width += kTitleLeftInset + title_->GetPreferredSize().width(); 410 title_bar_width += title_->GetPreferredSize().width();
376 if (close_->visible()) 411 if (close_->visible())
377 title_bar_width += close_->width() + 1; 412 title_bar_width += close_->width() + 1;
378 if (titlebar_extra_view_ != NULL) 413 if (titlebar_extra_view_ != NULL)
379 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); 414 title_bar_width += titlebar_extra_view_->GetPreferredSize().width();
380 gfx::Size size(client_size); 415 gfx::Size size(client_size);
381 size.SetToMax(gfx::Size(title_bar_width, 0)); 416 size.SetToMax(gfx::Size(title_bar_width, 0));
382 const gfx::Insets insets(GetInsets()); 417 const gfx::Insets insets(GetInsets());
383 size.Enlarge(insets.width(), insets.height()); 418 size.Enlarge(insets.width(), insets.height());
384 return size; 419 return size;
385 } 420 }
386 421
387 } // namespace views 422 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698