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

Unified Diff: chrome/browser/ui/views/validation_message_bubble_delegate.cc

Issue 329813003: Reland: Use labels to display views tab titles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Call AddChildView(title_) on Tab to prevent leaks. Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_unittest.cc ('k') | ui/gfx/text_constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/validation_message_bubble_delegate.cc
diff --git a/chrome/browser/ui/views/validation_message_bubble_delegate.cc b/chrome/browser/ui/views/validation_message_bubble_delegate.cc
index 107a873f268f3401969a5876c9474afe4fe8f8cb..f4e41f2453f39deaa78fff9ca3254366307a63e1 100644
--- a/chrome/browser/ui/views/validation_message_bubble_delegate.cc
+++ b/chrome/browser/ui/views/validation_message_bubble_delegate.cc
@@ -1,103 +1,102 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/views/validation_message_bubble_delegate.h"
-
-#include "grit/theme_resources.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/views/controls/image_view.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/widget/widget.h"
-
-// static
-const int ValidationMessageBubbleDelegate::kWindowMinWidth = 64;
-// static
-const int ValidationMessageBubbleDelegate::kWindowMaxWidth = 256;
-static const int kPadding = 0;
-static const int kIconTextMargin = 8;
-static const int kTextVerticalMargin = 4;
-
-ValidationMessageBubbleDelegate::ValidationMessageBubbleDelegate(
- const gfx::Rect& anchor_in_screen,
- const base::string16& main_text,
- const base::string16& sub_text,
- Observer* observer)
- : observer_(observer), width_(0), height_(0) {
- set_use_focusless(true);
- set_arrow(views::BubbleBorder::TOP_LEFT);
- SetAnchorRect(anchor_in_screen);
-
- ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
- views::ImageView* icon = new views::ImageView();
- icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT));
- gfx::Size size = icon->GetPreferredSize();
- icon->SetBounds(kPadding, kPadding, size.width(), size.height());
- AddChildView(icon);
-
- views::Label* label = new views::Label(
- main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont));
- label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- label->set_directionality_mode(views::Label::AUTO_DETECT_DIRECTIONALITY);
- int text_start_x = kPadding + size.width() + kIconTextMargin;
- int min_available = kWindowMinWidth - text_start_x - kPadding;
- int max_available = kWindowMaxWidth - text_start_x - kPadding;
- int label_width = label->GetPreferredSize().width();
- label->SetMultiLine(true);
- AddChildView(label);
-
- views::Label* sub_label = NULL;
- if (!sub_text.empty()) {
- sub_label = new views::Label(sub_text);
- sub_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- sub_label->set_directionality_mode(
- views::Label::AUTO_DETECT_DIRECTIONALITY);
- label_width = std::max(label_width, sub_label->GetPreferredSize().width());
- sub_label->SetMultiLine(true);
- AddChildView(sub_label);
- }
-
- if (label_width < min_available)
- label_width = min_available;
- else if (label_width > max_available)
- label_width = max_available;
- label->SetBounds(text_start_x, kPadding,
- label_width, label->GetHeightForWidth(label_width));
- int content_bottom = kPadding + label->height();
-
- if (sub_label) {
- sub_label->SetBounds(text_start_x,
- content_bottom + kTextVerticalMargin,
- label_width,
- sub_label->GetHeightForWidth(label_width));
- content_bottom += kTextVerticalMargin + sub_label->height();
- }
-
- width_ = text_start_x + label_width + kPadding;
- height_ = content_bottom + kPadding;
-}
-
-ValidationMessageBubbleDelegate::~ValidationMessageBubbleDelegate() {}
-
-void ValidationMessageBubbleDelegate::Close() {
- GetWidget()->Close();
- observer_ = NULL;
-}
-
-void ValidationMessageBubbleDelegate::SetPositionRelativeToAnchor(
- const gfx::Rect& anchor_in_screen) {
- SetAnchorRect(anchor_in_screen);
-}
-
-gfx::Size ValidationMessageBubbleDelegate::GetPreferredSize() const {
- return gfx::Size(width_, height_);
-}
-
-void ValidationMessageBubbleDelegate::DeleteDelegate() {
- delete this;
-}
-
-void ValidationMessageBubbleDelegate::WindowClosing() {
- if (observer_ != NULL)
- observer_->WindowClosing();
-}
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/validation_message_bubble_delegate.h"
+
+#include "grit/theme_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/widget/widget.h"
+
+// static
+const int ValidationMessageBubbleDelegate::kWindowMinWidth = 64;
+// static
+const int ValidationMessageBubbleDelegate::kWindowMaxWidth = 256;
+static const int kPadding = 0;
+static const int kIconTextMargin = 8;
+static const int kTextVerticalMargin = 4;
+
+ValidationMessageBubbleDelegate::ValidationMessageBubbleDelegate(
+ const gfx::Rect& anchor_in_screen,
+ const base::string16& main_text,
+ const base::string16& sub_text,
+ Observer* observer)
+ : observer_(observer), width_(0), height_(0) {
+ set_use_focusless(true);
+ set_arrow(views::BubbleBorder::TOP_LEFT);
+ SetAnchorRect(anchor_in_screen);
+
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+ views::ImageView* icon = new views::ImageView();
+ icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT));
+ gfx::Size size = icon->GetPreferredSize();
+ icon->SetBounds(kPadding, kPadding, size.width(), size.height());
+ AddChildView(icon);
+
+ views::Label* label = new views::Label(
+ main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont));
+ label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ label->set_directionality_mode(gfx::DIRECTIONALITY_FROM_TEXT);
+ int text_start_x = kPadding + size.width() + kIconTextMargin;
+ int min_available = kWindowMinWidth - text_start_x - kPadding;
+ int max_available = kWindowMaxWidth - text_start_x - kPadding;
+ int label_width = label->GetPreferredSize().width();
+ label->SetMultiLine(true);
+ AddChildView(label);
+
+ views::Label* sub_label = NULL;
+ if (!sub_text.empty()) {
+ sub_label = new views::Label(sub_text);
+ sub_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ sub_label->set_directionality_mode(gfx::DIRECTIONALITY_FROM_TEXT);
+ label_width = std::max(label_width, sub_label->GetPreferredSize().width());
+ sub_label->SetMultiLine(true);
+ AddChildView(sub_label);
+ }
+
+ if (label_width < min_available)
+ label_width = min_available;
+ else if (label_width > max_available)
+ label_width = max_available;
+ label->SetBounds(text_start_x, kPadding,
+ label_width, label->GetHeightForWidth(label_width));
+ int content_bottom = kPadding + label->height();
+
+ if (sub_label) {
+ sub_label->SetBounds(text_start_x,
+ content_bottom + kTextVerticalMargin,
+ label_width,
+ sub_label->GetHeightForWidth(label_width));
+ content_bottom += kTextVerticalMargin + sub_label->height();
+ }
+
+ width_ = text_start_x + label_width + kPadding;
+ height_ = content_bottom + kPadding;
+}
+
+ValidationMessageBubbleDelegate::~ValidationMessageBubbleDelegate() {}
+
+void ValidationMessageBubbleDelegate::Close() {
+ GetWidget()->Close();
+ observer_ = NULL;
+}
+
+void ValidationMessageBubbleDelegate::SetPositionRelativeToAnchor(
+ const gfx::Rect& anchor_in_screen) {
+ SetAnchorRect(anchor_in_screen);
+}
+
+gfx::Size ValidationMessageBubbleDelegate::GetPreferredSize() const {
+ return gfx::Size(width_, height_);
+}
+
+void ValidationMessageBubbleDelegate::DeleteDelegate() {
+ delete this;
+}
+
+void ValidationMessageBubbleDelegate::WindowClosing() {
+ if (observer_ != NULL)
+ observer_->WindowClosing();
+}
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_unittest.cc ('k') | ui/gfx/text_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698