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

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

Issue 14627004: Re-implement form validation message UI with native widgets (Views) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 7 years, 7 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/validation_message_bubble_delegate.h"
6
7 #include "grit/theme_resources.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/views/controls/image_view.h"
10 #include "ui/views/controls/label.h"
11
12 static const int kWindowMinWidth = 64;
13 static const int kWindowMaxWidth = 256;
14 static const int kPadding = 0;
15 static const int kIconTextMargin = 8;
16 static const int kTextVerticalMargin = 4;
17
18 ValidationMessageBubbleDelegate::ValidationMessageBubbleDelegate(
19 const gfx::Rect& anchor_in_screen,
20 const string16& main_text,
21 const string16& sub_text) {
22 set_use_focusless(true);
23 set_arrow(views::BubbleBorder::TOP_LEFT);
24 set_anchor_rect(anchor_in_screen);
25
26 ResourceBundle& bundle = ResourceBundle::GetSharedInstance();
27 views::ImageView* icon = new views::ImageView();
28 icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT));
29 gfx::Size size = icon->GetPreferredSize();
30 icon->SetBounds(kPadding, kPadding, size.width(), size.height());
31 AddChildView(icon);
32
33 views::Label* label = new views::Label(main_text);
34 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
35 label->SetFont(bundle.GetFont(ResourceBundle::MediumFont));
36 label->set_directionality_mode(views::Label::AUTO_DETECT_DIRECTIONALITY);
37 int text_start_x = kPadding + size.width() + kIconTextMargin;
38 int min_available = kWindowMinWidth - text_start_x - kPadding;
39 int max_available = kWindowMaxWidth - text_start_x - kPadding;
40 int label_width = label->GetPreferredSize().width();
41 label->SetMultiLine(true);
42 AddChildView(label);
43
44 views::Label* sub_label = NULL;
45 if (!sub_text.empty()) {
46 sub_label = new views::Label(sub_text);
47 sub_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
48 sub_label->set_directionality_mode(
49 views::Label::AUTO_DETECT_DIRECTIONALITY);
50 label_width = std::max(label_width, sub_label->GetPreferredSize().width());
51 sub_label->SetMultiLine(true);
52 AddChildView(sub_label);
53 }
54
55 if (label_width < min_available)
56 label_width = min_available;
57 else if (label_width > max_available)
58 label_width = max_available;
59 label->SetBounds(text_start_x, kPadding,
60 label_width, label->GetHeightForWidth(label_width));
61 int content_bottom = kPadding + label->height();
62
63 if (sub_label) {
64 sub_label->SetBounds(text_start_x,
65 content_bottom + kTextVerticalMargin,
66 label_width,
67 sub_label->GetHeightForWidth(label_width));
68 content_bottom += kTextVerticalMargin + sub_label->height();
69 }
70
71 width_ = text_start_x + label_width + kPadding;
72 height_ = content_bottom + kPadding;
73 }
74
75 gfx::Size ValidationMessageBubbleDelegate::GetPreferredSize() {
76 return gfx::Size(width_, height_);
77 }
78
79 void ValidationMessageBubbleDelegate::DeleteDelegate() {
80 delete this;
81 }
82
83 ValidationMessageBubbleDelegate::~ValidationMessageBubbleDelegate() {}
sky 2013/05/01 14:05:05 Make order match header.
tkent 2013/05/01 21:42:30 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698