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

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: delegate validity 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 #include "ui/views/widget/widget.h"
12
13 const int ValidationMessageBubbleDelegate::kWindowMinWidth = 64;
sky 2013/05/01 23:14:49 Prefix these with // static on the previous line.
tkent 2013/05/01 23:42:16 Done.
14 const int ValidationMessageBubbleDelegate::kWindowMaxWidth = 256;
15 static const int kPadding = 0;
16 static const int kIconTextMargin = 8;
17 static const int kTextVerticalMargin = 4;
18
19 ValidationMessageBubbleDelegate::ValidationMessageBubbleDelegate(
20 const gfx::Rect& anchor_in_screen,
21 const string16& main_text,
22 const string16& sub_text,
23 Observer* observer)
24 : observer_(observer) {
sky 2013/05/01 23:14:49 indent 2 more, and initialize width_/height_.
tkent 2013/05/01 23:42:16 Done.
25 set_use_focusless(true);
26 set_arrow(views::BubbleBorder::TOP_LEFT);
27 set_anchor_rect(anchor_in_screen);
28
29 ResourceBundle& bundle = ResourceBundle::GetSharedInstance();
30 views::ImageView* icon = new views::ImageView();
31 icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT));
32 gfx::Size size = icon->GetPreferredSize();
33 icon->SetBounds(kPadding, kPadding, size.width(), size.height());
34 AddChildView(icon);
35
36 views::Label* label = new views::Label(main_text);
37 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
38 label->SetFont(bundle.GetFont(ResourceBundle::MediumFont));
39 label->set_directionality_mode(views::Label::AUTO_DETECT_DIRECTIONALITY);
40 int text_start_x = kPadding + size.width() + kIconTextMargin;
41 int min_available = kWindowMinWidth - text_start_x - kPadding;
42 int max_available = kWindowMaxWidth - text_start_x - kPadding;
43 int label_width = label->GetPreferredSize().width();
44 label->SetMultiLine(true);
45 AddChildView(label);
46
47 views::Label* sub_label = NULL;
48 if (!sub_text.empty()) {
49 sub_label = new views::Label(sub_text);
50 sub_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
51 sub_label->set_directionality_mode(
52 views::Label::AUTO_DETECT_DIRECTIONALITY);
53 label_width = std::max(label_width, sub_label->GetPreferredSize().width());
54 sub_label->SetMultiLine(true);
55 AddChildView(sub_label);
56 }
57
58 if (label_width < min_available)
59 label_width = min_available;
60 else if (label_width > max_available)
61 label_width = max_available;
62 label->SetBounds(text_start_x, kPadding,
63 label_width, label->GetHeightForWidth(label_width));
64 int content_bottom = kPadding + label->height();
65
66 if (sub_label) {
67 sub_label->SetBounds(text_start_x,
68 content_bottom + kTextVerticalMargin,
69 label_width,
70 sub_label->GetHeightForWidth(label_width));
71 content_bottom += kTextVerticalMargin + sub_label->height();
72 }
73
74 width_ = text_start_x + label_width + kPadding;
75 height_ = content_bottom + kPadding;
76 }
77
78 ValidationMessageBubbleDelegate::~ValidationMessageBubbleDelegate() {}
79
80 void ValidationMessageBubbleDelegate::Hide() {
81 GetWidget()->Hide();
82 observer_ = NULL;
83 }
84
85 gfx::Size ValidationMessageBubbleDelegate::GetPreferredSize() {
86 return gfx::Size(width_, height_);
87 }
88
89 void ValidationMessageBubbleDelegate::DeleteDelegate() {
90 delete this;
91 }
92
93 void ValidationMessageBubbleDelegate::WindowClosing() {
94 if (observer_ != NULL)
95 observer_->WindowClosing();
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698