summaryrefslogtreecommitdiffstats
path: root/ui/views
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-13 14:11:09 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-13 14:11:09 +0000
commitb3c963fd30ca4d0a9aab5bb619c43ac63a169d6b (patch)
tree5df14bb34fac6cad15b0c93c4ac46c31fab70932 /ui/views
parent6f21c9d7ecf47b401e04b0c47b11ea263da99fca (diff)
downloadchromium_src-b3c963fd30ca4d0a9aab5bb619c43ac63a169d6b.zip
chromium_src-b3c963fd30ca4d0a9aab5bb619c43ac63a169d6b.tar.gz
chromium_src-b3c963fd30ca4d0a9aab5bb619c43ac63a169d6b.tar.bz2
views: Add a new ctor to MessageBoxView that takes only a InitParams.
This simplifies many consumers of this API. R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/10378086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r--ui/views/controls/message_box_view.cc44
-rw-r--r--ui/views/controls/message_box_view.h20
-rw-r--r--ui/views/examples/message_box_example.cc6
3 files changed, 32 insertions, 38 deletions
diff --git a/ui/views/controls/message_box_view.cc b/ui/views/controls/message_box_view.cc
index affe912..e69891f 100644
--- a/ui/views/controls/message_box_view.cc
+++ b/ui/views/controls/message_box_view.cc
@@ -21,10 +21,10 @@
#include "ui/views/widget/widget.h"
#include "ui/views/window/client_view.h"
-const int kDefaultMessageWidth = 320;
-
namespace {
+const int kDefaultMessageWidth = 320;
+
// Paragraph separators are defined in
// http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBidiClass.txt
//
@@ -96,25 +96,21 @@ namespace views {
///////////////////////////////////////////////////////////////////////////////
// MessageBoxView, public:
-MessageBoxView::MessageBoxView(int options,
- const string16& message,
- const string16& default_prompt,
- int message_width)
- : prompt_field_(NULL),
- icon_(NULL),
- checkbox_(NULL),
- message_width_(message_width) {
- Init(options, message, default_prompt);
+MessageBoxView::InitParams::InitParams(const string16& message)
+ : options(NO_OPTIONS),
+ message(message),
+ message_width(kDefaultMessageWidth) {
+}
+
+MessageBoxView::InitParams::~InitParams() {
}
-MessageBoxView::MessageBoxView(int options,
- const string16& message,
- const string16& default_prompt)
+MessageBoxView::MessageBoxView(const InitParams& params)
: prompt_field_(NULL),
icon_(NULL),
checkbox_(NULL),
- message_width_(kDefaultMessageWidth) {
- Init(options, message, default_prompt);
+ message_width_(params.message_width) {
+ Init(params);
}
MessageBoxView::~MessageBoxView() {}
@@ -194,16 +190,14 @@ bool MessageBoxView::AcceleratorPressed(const ui::Accelerator& accelerator) {
///////////////////////////////////////////////////////////////////////////////
// MessageBoxView, private:
-void MessageBoxView::Init(int options,
- const string16& message,
- const string16& prompt) {
- if (options & DETECT_DIRECTIONALITY) {
+void MessageBoxView::Init(const InitParams& params) {
+ if (params.options & DETECT_DIRECTIONALITY) {
std::vector<string16> texts;
- SplitStringIntoParagraphs(message, &texts);
+ SplitStringIntoParagraphs(params.message, &texts);
// If the text originates from a web page, its alignment is based on its
// first character with strong directionality.
base::i18n::TextDirection message_direction =
- base::i18n::GetFirstStrongCharacterDirection(message);
+ base::i18n::GetFirstStrongCharacterDirection(params.message);
Label::Alignment alignment =
(message_direction == base::i18n::RIGHT_TO_LEFT) ?
Label::ALIGN_RIGHT : Label::ALIGN_LEFT;
@@ -216,16 +210,16 @@ void MessageBoxView::Init(int options,
message_labels_.push_back(message_label);
}
} else {
- Label* message_label = new Label(message);
+ Label* message_label = new Label(params.message);
message_label->SetMultiLine(true);
message_label->SetAllowCharacterBreak(true);
message_label->SetHorizontalAlignment(Label::ALIGN_LEFT);
message_labels_.push_back(message_label);
}
- if (options & HAS_PROMPT_FIELD) {
+ if (params.options & HAS_PROMPT_FIELD) {
prompt_field_ = new Textfield;
- prompt_field_->SetText(prompt);
+ prompt_field_->SetText(params.default_prompt);
}
ResetLayoutManager();
diff --git a/ui/views/controls/message_box_view.h b/ui/views/controls/message_box_view.h
index 7325a05..c1a6baa 100644
--- a/ui/views/controls/message_box_view.h
+++ b/ui/views/controls/message_box_view.h
@@ -6,7 +6,6 @@
#define UI_VIEWS_CONTROLS_MESSAGE_BOX_VIEW_H_
#pragma once
-#include <string>
#include <vector>
#include "base/string16.h"
@@ -37,14 +36,17 @@ class VIEWS_EXPORT MessageBoxView : public View {
HAS_PROMPT_FIELD = 1 << 1,
};
- MessageBoxView(int options,
- const string16& message,
- const string16& default_prompt,
- int message_width);
+ struct InitParams {
+ explicit InitParams(const string16& message);
+ ~InitParams();
- MessageBoxView(int options,
- const string16& message,
- const string16& default_prompt);
+ uint16 options;
+ string16 message;
+ string16 default_prompt;
+ int message_width;
+ };
+
+ explicit MessageBoxView(const InitParams& params);
virtual ~MessageBoxView();
@@ -84,7 +86,7 @@ class VIEWS_EXPORT MessageBoxView : public View {
private:
// Sets up the layout manager and initializes the message labels and prompt
// field. This should only be called once, from the constructor.
- void Init(int options, const string16& message, const string16& prompt);
+ void Init(const InitParams& params);
// Sets up the layout manager based on currently initialized views. Should be
// called when a view is initialized or changed.
diff --git a/ui/views/examples/message_box_example.cc b/ui/views/examples/message_box_example.cc
index c718077..e50d22a 100644
--- a/ui/views/examples/message_box_example.cc
+++ b/ui/views/examples/message_box_example.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -20,9 +20,7 @@ MessageBoxExample::~MessageBoxExample() {
void MessageBoxExample::CreateExampleView(View* container) {
message_box_view_ = new MessageBoxView(
- views::MessageBoxView::NO_OPTIONS,
- ASCIIToUTF16("Message Box Message"),
- ASCIIToUTF16("Default Prompt"));
+ MessageBoxView::InitParams(ASCIIToUTF16("Hello, world!")));
status_ = new TextButton(this, ASCIIToUTF16("Show Status"));
toggle_ = new TextButton(this, ASCIIToUTF16("Toggle Checkbox"));