summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authoralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 02:12:08 +0000
committeralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 02:12:08 +0000
commitfc9e7f5981d3b4a87a9657c041dd09d8cbd086bf (patch)
treee131b6a69ffd21bc57603acf1ed12bebc4377e00 /ui
parentc7e95b41a0f80c8db514c221abe70044ae620edd (diff)
downloadchromium_src-fc9e7f5981d3b4a87a9657c041dd09d8cbd086bf.zip
chromium_src-fc9e7f5981d3b4a87a9657c041dd09d8cbd086bf.tar.gz
chromium_src-fc9e7f5981d3b4a87a9657c041dd09d8cbd086bf.tar.bz2
Revert 188637 "Added text line limits to collapsed and expanded ..."
It appears that r188637 is causing flakiness of ash_unittests on Win8 Aura: http://build.chromium.org/p/chromium.win/builders/Win8%20Aura/builds/3400 > Added text line limits to collapsed and expanded notifications. > > This is done through a new BoundedLabel views::Label subclass that > supports a max_lines value. This class comes with unit tests covering > its basic functionality. > > Also, the Notifications Galore! test app was updated to include test > notifications with long titles, long messages, and long items which can > be used for manual tests of the line limits. > > As with the rest of the collapse/expand functionality currently > committed, this only applies to the notification center. Notification > toasts are currently still always expanded and text line limits have not > been tested for them. > > There are some known issues with incorrect notification card sizes in > the notification center after some sequence of create/destroy > operations, and these will be addressed in a separate change list. > > BUG=161098,168939,168940 > R=dewittj@chromium.org > TBR=mukai@chromium.org > > > Review URL: https://chromiumcodereview.appspot.com/12742005 TBR=dharcourt@chromium.org Review URL: https://codereview.chromium.org/12757003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188663 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/message_center/message_center.gyp24
-rw-r--r--ui/message_center/run_all_unittests.cc42
-rw-r--r--ui/message_center/views/bounded_label.cc157
-rw-r--r--ui/message_center/views/bounded_label.h67
-rw-r--r--ui/message_center/views/bounded_label_unittest.cc224
-rw-r--r--ui/message_center/views/notification_view.cc29
-rw-r--r--ui/message_center/views/notification_view.h9
7 files changed, 25 insertions, 527 deletions
diff --git a/ui/message_center/message_center.gyp b/ui/message_center/message_center.gyp
index 4bea413..00139ec 100644
--- a/ui/message_center/message_center.gyp
+++ b/ui/message_center/message_center.gyp
@@ -46,8 +46,6 @@
'notification_types.h',
'notifier_settings.cc',
'notifier_settings.h',
- 'views/bounded_label.cc',
- 'views/bounded_label.h',
'views/message_bubble_base.cc',
'views/message_bubble_base.h',
'views/message_center_bubble.cc',
@@ -78,35 +76,23 @@
],
}],
],
- }, # target_name: message_center
+ },
{
'target_name': 'message_center_unittests',
'type': 'executable',
'dependencies': [
+ '../../base/base.gyp:base',
+ '../../base/base.gyp:run_all_unittests',
'../../base/base.gyp:test_support_base',
'../../skia/skia.gyp:skia',
'../../testing/gtest.gyp:gtest',
+ '../ui.gyp:ui',
'message_center',
],
'sources': [
'message_center_tray_unittest.cc',
'notification_list_unittest.cc',
- 'run_all_unittests.cc',
- ],
- 'conditions': [
- ['toolkit_views==1', {
- 'dependencies': [
- # The BoundedLabel unit tests use fonts, and fonts require the
- # compositor and its test support.
- '../compositor/compositor.gyp:compositor',
- '../compositor/compositor.gyp:compositor_test_support',
- '../views/views.gyp:views',
- ],
- 'sources': [
- 'views/bounded_label_unittest.cc',
- ],
- }],
],
- }, # target_name: message_center_unittests
+ },
],
}
diff --git a/ui/message_center/run_all_unittests.cc b/ui/message_center/run_all_unittests.cc
deleted file mode 100644
index 9e01991..0000000
--- a/ui/message_center/run_all_unittests.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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 "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/test/test_suite.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/base/ui_base_paths.h"
-#include "ui/compositor/compositor_setup.h"
-#include "ui/compositor/test/compositor_test_support.h"
-#include "ui/views/view.h"
-
-class MessageCenterTestSuite : public base::TestSuite {
- public:
- MessageCenterTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
-
- protected:
- virtual void Initialize() OVERRIDE;
- virtual void Shutdown() OVERRIDE;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MessageCenterTestSuite);
-};
-
-void MessageCenterTestSuite::Initialize() {
- base::TestSuite::Initialize();
-
- ui::RegisterPathProvider();
- ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
-
- ui::CompositorTestSupport::Initialize();
- ui::SetupTestCompositor();
-}
-
-void MessageCenterTestSuite::Shutdown() {
- ui::CompositorTestSupport::Terminate();
-}
-
-int main(int argc, char** argv) {
- return MessageCenterTestSuite(argc, argv).Run();
-}
diff --git a/ui/message_center/views/bounded_label.cc b/ui/message_center/views/bounded_label.cc
deleted file mode 100644
index f9c71b3..0000000
--- a/ui/message_center/views/bounded_label.cc
+++ /dev/null
@@ -1,157 +0,0 @@
-// 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.
-
-#include "ui/message_center/views/bounded_label.h"
-
-#include <limits>
-
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#include "ui/base/text/text_elider.h"
-#include "ui/gfx/canvas.h"
-
-namespace message_center {
-
-BoundedLabel::BoundedLabel(string16 text, size_t max_lines)
- : views::Label(text, gfx::Font()) {
- Init(max_lines);
-}
-
-BoundedLabel::BoundedLabel(string16 text, gfx::Font font, size_t max_lines)
- : views::Label(text, font) {
- Init(max_lines);
-}
-
-BoundedLabel::~BoundedLabel() {
-}
-
-void BoundedLabel::SetMaxLines(size_t lines) {
- is_preferred_lines_valid_ = false;
- is_text_size_valid_ = false;
- max_lines_ = lines;
-}
-
-size_t BoundedLabel::GetMaxLines() {
- return max_lines_;
-}
-
-size_t BoundedLabel::GetPreferredLines() {
- if (!is_preferred_lines_valid_) {
- int wrap_width = width() - GetInsets().width();
- int unlimited_lines = std::numeric_limits<size_t>::max();
- preferred_lines_ = SplitLines(wrap_width, unlimited_lines).size();
- is_preferred_lines_valid_ = true;
- }
- return preferred_lines_;
-}
-
-int BoundedLabel::GetHeightForWidth(int width) {
- gfx::Insets insets = GetInsets();
- return GetTextHeightForWidth(width - insets.width()) + insets.height();
-}
-
-gfx::Size BoundedLabel::GetTextSize() const {
- if (!is_text_size_valid_) {
- text_size_.set_width(width() - GetInsets().width());
- text_size_.set_height(GetTextHeightForWidth(text_size_.width()));
- is_text_size_valid_ = true;
- }
- return text_size_;
-}
-
-void BoundedLabel::OnBoundsChanged(const gfx::Rect& previous_bounds) {
- is_preferred_lines_valid_ = false;
- is_text_size_valid_ = false;
-}
-
-void BoundedLabel::PaintText(gfx::Canvas* canvas,
- const string16& paint_text,
- const gfx::Rect& text_bounds,
- int flags) {
- gfx::Insets insets = GetInsets();
- gfx::Rect bounds(gfx::Point(insets.left(), insets.top()), GetTextSize());
- string16 text = JoinString(SplitLines(bounds.width(), max_lines_), '\n');
- views::Label::PaintText(canvas, text, bounds, GetTextFlags());
-}
-
-void BoundedLabel::Init(size_t max_lines) {
- SetMultiLine(true);
- SetAllowCharacterBreak(true);
- SetElideBehavior(views::Label::ELIDE_AT_END);
- max_lines_ = max_lines;
- is_preferred_lines_valid_ = false;
- is_text_size_valid_ = false;
-}
-
-int BoundedLabel::GetTextFlags() const {
- int flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::CHARACTER_BREAK;
-
- // We can't use subpixel rendering if the background is non-opaque.
- if (SkColorGetA(background_color()) != 0xFF)
- flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
-
- if (directionality_mode() == AUTO_DETECT_DIRECTIONALITY) {
- base::i18n::TextDirection direction =
- base::i18n::GetFirstStrongCharacterDirection(text());
- if (direction == base::i18n::RIGHT_TO_LEFT)
- flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
- else
- flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
- }
-
- switch (horizontal_alignment()) {
- case gfx::ALIGN_LEFT:
- flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
- break;
- case gfx::ALIGN_CENTER:
- flags |= gfx::Canvas::TEXT_ALIGN_CENTER;
- break;
- case gfx::ALIGN_RIGHT:
- flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
- break;
- }
-
- return flags;
-}
-
-int BoundedLabel::GetTextHeightForWidth(int width) const {
- int height = font().GetHeight();
- width = std::max(width, 0);
- string16 text = JoinString(SplitLines(width, max_lines_), '\n');
- gfx::Canvas::SizeStringInt(text, font(), &width, &height, GetTextFlags());
- return height;
-}
-
-std::vector<string16> BoundedLabel::SplitLines(int width,
- size_t max_lines) const {
- // Adjust max_lines so (max_lines + 1) * line_height <= INT_MAX, then use the
- // adjusted max_lines to get a max_height of (max_lines + 1) * line_height.
- size_t max_height = std::numeric_limits<int>::max();
- size_t line_height = std::max(font().GetHeight(), 2); // At least 2 pixels!
- max_lines = std::min(max_lines, max_height / line_height - 1);
- max_height = (max_lines + 1) * line_height;
-
- // Split. Do not use ui::WRAP_LONG_WORDS instead of ui::IGNORE_LONG_WORDS
- // below as this may cause ui::ElideRectangleText() to go into an infinite
- // loop for small width values.
- std::vector<string16> lines;
- ui::ElideRectangleText(text(), font(), width, max_height,
- ui::IGNORE_LONG_WORDS, &lines);
-
- // Elide if necessary.
- if (lines.size() > max_lines) {
- // Add an ellipsis to the last line. If this ellipsis makes the last line
- // too wide, that line will be further elided by the ui::ElideText below,
- // so for example "ABC" could become "ABC..." here and "AB..." below.
- string16 last = lines[max_lines - 1] + UTF8ToUTF16(ui::kEllipsis);
- lines.resize(max_lines - 1);
- lines.push_back((font().GetStringWidth(last) > width) ?
- ui::ElideText(last, font(), width, ui::ELIDE_AT_END) :
- last);
- }
-
- return lines;
-}
-
-} // namespace message_center
diff --git a/ui/message_center/views/bounded_label.h b/ui/message_center/views/bounded_label.h
deleted file mode 100644
index e79edff..0000000
--- a/ui/message_center/views/bounded_label.h
+++ /dev/null
@@ -1,67 +0,0 @@
-// 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.
-
-#ifndef UI_MESSAGE_CENTER_BOUNDED_LABEL_H_
-#define UI_MESSAGE_CENTER_BOUNDED_LABEL_H_
-
-#include "testing/gtest/include/gtest/gtest_prod.h"
-#include "ui/message_center/message_center_export.h"
-#include "ui/views/controls/label.h"
-
-namespace message_center {
-
-// BoundedLabels display text up to a maximum number of lines, with ellipsis at
-// the end of the last line for any omitted text. The font, text, multiline
-// behavior, character break behavior, elide behavior, and focus border of
-// instances of this views::Label subclass cannot be changed, so the following
-// views::Label methods should never be called with instances of this class:
-//
-// SetFont()
-// SetText()
-// SetMultiLine()
-// SetAllowCharacterBreak()
-// SetElideBehavior()
-// SetHasFocusBorder()
-//
-class MESSAGE_CENTER_EXPORT BoundedLabel : public views::Label {
- public:
- BoundedLabel(string16 text, size_t max_lines);
- BoundedLabel(string16 text, gfx::Font font, size_t max_lines);
- virtual ~BoundedLabel();
-
- void SetMaxLines(size_t lines);
- size_t GetMaxLines();
- size_t GetPreferredLines();
-
- virtual int GetHeightForWidth(int width) OVERRIDE;
-
- protected:
- // Overridden from views::Label.
- virtual gfx::Size GetTextSize() const OVERRIDE;
- virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
- virtual void PaintText(gfx::Canvas* canvas,
- const string16& text,
- const gfx::Rect& text_bounds,
- int flags) OVERRIDE;
-
- private:
- friend class BoundedLabelTest;
-
- void Init(size_t max_lines);
- int GetTextFlags() const;
- int GetTextHeightForWidth(int width) const;
- std::vector<string16> SplitLines(int width, size_t max_lines) const;
-
- size_t max_lines_;
- size_t preferred_lines_;
- bool is_preferred_lines_valid_;
- mutable gfx::Size text_size_;
- mutable bool is_text_size_valid_;
-
- DISALLOW_COPY_AND_ASSIGN(BoundedLabel);
-};
-
-} // namespace message_center
-
-#endif // UI_MESSAGE_CENTER_BOUNDED_LABEL_H_
diff --git a/ui/message_center/views/bounded_label_unittest.cc b/ui/message_center/views/bounded_label_unittest.cc
deleted file mode 100644
index aac0c5b..0000000
--- a/ui/message_center/views/bounded_label_unittest.cc
+++ /dev/null
@@ -1,224 +0,0 @@
-// 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 "ui/message_center/views/bounded_label.h"
-
-#include <limits>
-
-#include "base/string_util.h"
-#include "base/strings/string_split.h"
-#include "base/utf_string_conversions.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/font.h"
-#include "ui/views/controls/label.h"
-
-namespace message_center {
-
-/* Test fixture declaration ***************************************************/
-
-class BoundedLabelTest : public testing::Test {
- public:
- BoundedLabelTest();
- virtual ~BoundedLabelTest();
-
- // Replaces all occurences of three periods ("...") in the specified string
- // with an ellipses character (UTF8 "\xE2\x80\xA6") and returns a string16
- // with the results. This allows test strings to be specified as ASCII const
- // char* strings, making tests more readable and easier to write.
- string16 ToString(const char* string);
-
- // Converts the specified elision width to pixels. To make tests somewhat
- // independent of the fonts of the platform on which they're run, the elision
- // widths are specified as XYZ integers, with the corresponding width in
- // pixels being X times the width of digit characters plus Y times the width
- // of spaces plus Z times the width of ellipses in the default font of the
- // test plaform. It is assumed that all digits have the same width in that
- // font, that this width is greater than the width of spaces, and that the
- // width of 3 digits is greater than the width of ellipses.
- int ToPixels(int width);
-
- // Exercise BounderLabel::SplitLines() using the fixture's test label.
- string16 SplitLines(int width);
-
- // Exercise BounderLabel::GetPreferredLines() using the fixture's test label.
- int GetPreferredLines(int width);
-
- protected:
- // Creates a label to test with. Returns this fixture, which can be used to
- // test the newly created label using the exercise methods above.
- BoundedLabelTest& Label(string16 text, size_t lines);
-
- private:
- gfx::Font font_; // The default font, which will be used for tests.
- int digit_pixels_;
- int space_pixels_;
- int ellipsis_pixels_;
- scoped_ptr<BoundedLabel> label_;
-};
-
-/* Test fixture definition ****************************************************/
-
-BoundedLabelTest::BoundedLabelTest() {
- digit_pixels_ = font_.GetStringWidth(UTF8ToUTF16("0"));
- space_pixels_ = font_.GetStringWidth(UTF8ToUTF16(" "));
- ellipsis_pixels_ = font_.GetStringWidth(UTF8ToUTF16("\xE2\x80\xA6"));
-}
-
-BoundedLabelTest::~BoundedLabelTest() {
-}
-
-string16 BoundedLabelTest::ToString(const char* string) {
- const string16 periods = UTF8ToUTF16("...");
- const string16 ellipses = UTF8ToUTF16("\xE2\x80\xA6");
- string16 result = UTF8ToUTF16(string);
- ReplaceSubstringsAfterOffset(&result, 0, periods, ellipses);
- return result;
-}
-
-int BoundedLabelTest::ToPixels(int width) {
- return digit_pixels_ * width / 100 +
- space_pixels_ * (width % 100) / 10 +
- ellipsis_pixels_ * (width % 10);
-}
-
-string16 BoundedLabelTest::SplitLines(int width) {
- return JoinString(label_->SplitLines(width, label_->GetMaxLines()), '\n');
-}
-
-int BoundedLabelTest::GetPreferredLines(int width) {
- label_->SetBounds(0, 0, width, font_.GetHeight() * label_->GetMaxLines());
- return label_->GetPreferredLines();
-}
-
-BoundedLabelTest& BoundedLabelTest::Label(string16 text, size_t lines) {
- label_.reset(new BoundedLabel(text, font_, lines));
- return *this;
-}
-
-/* Test macro definitions *****************************************************/
-
-#define TEST_SPLIT_LINES(expected, text, width, lines) \
- EXPECT_EQ(ToString(expected), \
- Label(ToString(text), lines).SplitLines(ToPixels(width)))
-
-#define TEST_GET_PREFERRED_LINES(expected, text, width, lines) \
- EXPECT_EQ(expected, \
- Label(ToString(text), lines).GetPreferredLines(ToPixels(width)))
-
-/* Elision tests **************************************************************/
-
-TEST_F(BoundedLabelTest, ElisionTest) {
- // One word per line: No ellision should be made when not necessary.
- TEST_SPLIT_LINES("123", "123", 301, 1);
- TEST_SPLIT_LINES("123", "123", 301, 2);
- TEST_SPLIT_LINES("123", "123", 301, 3);
- TEST_SPLIT_LINES("123\n456", "123 456", 0, 2); // 301, 2);
- TEST_SPLIT_LINES("123\n456", "123 456", 301, 3);
- TEST_SPLIT_LINES("123\n456\n789", "123 456 789", 301, 3);
-
- // One word per line: Ellisions should be made when necessary.
- TEST_SPLIT_LINES("123...", "123 456", 301, 1);
- TEST_SPLIT_LINES("123...", "123 456 789", 301, 1);
- TEST_SPLIT_LINES("123\n456...", "123 456 789", 301, 2);
-
- // Two words per line: No ellision should be made when not necessary.
- TEST_SPLIT_LINES("123 456", "123 456", 621, 1);
- TEST_SPLIT_LINES("123 456", "123 456", 621, 2);
- TEST_SPLIT_LINES("123 456", "123 456", 621, 3);
- TEST_SPLIT_LINES("123 456\n789 012", "123 456 789 012", 621, 2);
- TEST_SPLIT_LINES("123 456\n789 012", "123 456 789 012", 621, 3);
- TEST_SPLIT_LINES("123 456\n789 012\n345 678",
- "123 456 789 012 345 678", 621, 3);
-
- // Two words per line: Ellisions should be made when necessary.
- TEST_SPLIT_LINES("123 456...", "123 456 789 012", 621, 1);
- TEST_SPLIT_LINES("123 456...", "123 456 789 012 345 678", 621, 1);
- TEST_SPLIT_LINES("123 456\n789 012...", "123 456 789 012 345 678", 621, 2);
-
- // Single trailing spaces: No ellipses should be added.
- TEST_SPLIT_LINES("123", "123 ", 301, 1);
- TEST_SPLIT_LINES("123\n456", "123 456 ", 301, 2);
- TEST_SPLIT_LINES("123\n456\n789", "123 456 789 ", 301, 3);
- TEST_SPLIT_LINES("123 456", "123 456 ", 611, 1);
- TEST_SPLIT_LINES("123 456\n789 012", "123 456 789 012 ", 611, 2);
- TEST_SPLIT_LINES("123 456\n789 012\n345 678",
- "123 456 789 012 345 678 ", 611, 3);
-
- // Multiple trailing spaces: No ellipses should be added.
- TEST_SPLIT_LINES("123", "123 ", 301, 1);
- TEST_SPLIT_LINES("123\n456", "123 456 ", 301, 2);
- TEST_SPLIT_LINES("123\n456\n789", "123 456 789 ", 301, 3);
- TEST_SPLIT_LINES("123 456", "123 456 ", 611, 1);
- TEST_SPLIT_LINES("123 456\n789 012", "123 456 789 012 ", 611, 2);
- TEST_SPLIT_LINES("123 456\n789 012\n345 678",
- "123 456 789 012 345 678 ", 611, 3);
-
- // Multiple spaces between words on the same line: Spaces should be preserved.
- // Test cases for single spaces between such words are included in the "Two
- // words per line" sections above.
- TEST_SPLIT_LINES("123 456", "123 456", 621, 1);
- TEST_SPLIT_LINES("123 456...", "123 456 789 012", 631, 1);
- TEST_SPLIT_LINES("123 456\n789 012", "123 456 789 012", 631, 2);
- TEST_SPLIT_LINES("123 456...", "123 456 789 012 345 678", 621, 1);
- TEST_SPLIT_LINES("123 456\n789 012...",
- "123 456 789 012 345 678", 631, 2);
- TEST_SPLIT_LINES("123 456\n789 012\n345 678",
- "123 456 789 012 345 678", 641, 3);
-
- // Multiple spaces between words split across lines: Spaces should be removed
- // even if lines are wide enough to include those spaces. Test cases for
- // single spaces between such words are included in the "Two words per line"
- // sections above.
- TEST_SPLIT_LINES("123\n456", "123 456", 321, 2);
- TEST_SPLIT_LINES("123\n456", "123 456", 391, 2);
- TEST_SPLIT_LINES("123\n456...", "123 456 789", 321, 2);
- TEST_SPLIT_LINES("123\n456...", "123 456 789", 391, 2);
- TEST_SPLIT_LINES("123 456\n789 012", "123 456 789 012", 641, 2);
- TEST_SPLIT_LINES("123 456\n789 012...", "123 456 789 012 345 678",
- 641, 2);
-
- // TODO(dharcourt): Add test cases to verify that:
- // - Spaces before elisions are removed
- // - Leading spaces are preserved
- // - Words are split when they are longer than lines
- // - Words are clipped when they are longer than the last line
- // - No blank line are created before or after clipped word
- // - Spaces at the end of the text are removed
-
- // TODO(dharcourt): Add test cases for:
- // - Empty and very large strings
- // - Zero and very large max lines values
- // - Other input boundary conditions
- // TODO(dharcourt): Add some randomly generated fuzz test cases.
-
-}
-
-/* GetPreferredLinesTest ******************************************************/
-
-TEST_F(BoundedLabelTest, GetPreferredLinesTest) {
- // Zero, small, and negative width values should yield one word per line.
- TEST_GET_PREFERRED_LINES(2, "123 456", 0, 1);
- TEST_GET_PREFERRED_LINES(2, "123 456", 1, 1);
- TEST_GET_PREFERRED_LINES(2, "123 456", 2, 1);
- TEST_GET_PREFERRED_LINES(2, "123 456", 3, 1);
- TEST_GET_PREFERRED_LINES(2, "123 456", -1, 1);
- TEST_GET_PREFERRED_LINES(2, "123 456", -2, 1);
- TEST_GET_PREFERRED_LINES(2, "123 456", std::numeric_limits<int>::min(), 1);
-
- // Large width values should yield all words on one line.
- TEST_GET_PREFERRED_LINES(1, "123 456", 610, 1);
- TEST_GET_PREFERRED_LINES(1, "123 456", std::numeric_limits<int>::max(), 1);
-}
-
-/* Other tests ****************************************************************/
-
-// TODO(dharcourt): Add test cases to verify that:
-// - SetMaxLines() affects GetMaxLines(), GetHeightForWidth(), GetTextSize(),
-// and GetTextLines() return values but not GetPreferredLines() or
-// GetTextSize() ones.
-// - Bound changes affects GetPreferredLines(), GetTextSize(), and
-// GetTextLines() return values.
-// - GetTextFlags are as expected.
-
-} // namespace message_center
diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc
index 6ca65dd..22ef717 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -18,7 +18,6 @@
#include "ui/message_center/notification.h"
#include "ui/message_center/notification_change_observer.h"
#include "ui/message_center/notification_types.h"
-#include "ui/message_center/views/bounded_label.h"
#include "ui/message_center/views/message_simple_view.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/controls/button/image_button.h"
@@ -341,9 +340,6 @@ NotificationView::NotificationView(const Notification& notification,
NotificationChangeObserver* observer,
bool expanded)
: MessageView(notification, observer, expanded) {
- // As we build the view, we'll see if any part of it is expandable.
- bool expandable = false;
-
// Create the opaque background that's above the view's shadow.
background_view_ = new views::View();
background_view_->set_background(
@@ -357,9 +353,13 @@ NotificationView::NotificationView(const Notification& notification,
// Create the title view if appropriate.
title_view_ = NULL;
if (!notification.title().empty()) {
- gfx::Font font = views::Label().font().DeriveFont(4);
- title_view_ = new BoundedLabel(notification.title(), font, 1);
+ title_view_ = new views::Label(notification.title());
title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ if (is_expanded())
+ title_view_->SetMultiLine(true);
+ else
+ title_view_->SetElideBehavior(views::Label::ELIDE_AT_END);
+ title_view_->SetFont(title_view_->font().DeriveFont(4));
title_view_->SetEnabledColor(kTitleColor);
title_view_->SetBackgroundColor(kTitleBackgroundColor);
title_view_->set_border(MakeBorder(kTextTopPadding, 3));
@@ -369,16 +369,18 @@ NotificationView::NotificationView(const Notification& notification,
// Create the message view if appropriate.
message_view_ = NULL;
if (!notification.message().empty()) {
- size_t lines = (is_expanded() && notification.image().IsEmpty()) ? 7 : 2;
- message_view_ = new BoundedLabel(notification.message(), lines);
+ message_view_ = new views::Label(notification.message());
message_view_->SetVisible(!is_expanded() || !notification.items().size());
message_view_->set_collapse_when_hidden(true);
message_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ if (is_expanded())
+ message_view_->SetMultiLine(true);
+ else
+ message_view_->SetElideBehavior(views::Label::ELIDE_AT_END);
message_view_->SetEnabledColor(kMessageColor);
message_view_->SetBackgroundColor(kMessageBackgroundColor);
message_view_->set_border(MakeBorder(0, 3));
top_view_->AddChildView(message_view_);
- expandable = (message_view_->GetPreferredLines() > lines);
}
// Create the list item views (up to a maximum).
@@ -389,7 +391,6 @@ NotificationView::NotificationView(const Notification& notification,
item_view->set_border(MakeBorder(0, 4));
item_views_.push_back(item_view);
top_view_->AddChildView(item_view);
- expandable = true;
}
// Create the notification icon view.
@@ -407,7 +408,6 @@ NotificationView::NotificationView(const Notification& notification,
image_view_ = new ProportionalImageView(notification.image().AsImageSkia());
image_view_->SetVisible(is_expanded());
bottom_view_->AddChildView(image_view_);
- expandable = true;
}
// Create action buttons if appropriate.
@@ -425,6 +425,7 @@ NotificationView::NotificationView(const Notification& notification,
}
// Hide the expand button if appropriate.
+ bool expandable = item_views_.size() || image_view_;
expand_button()->SetVisible(expandable && !is_expanded());
// Put together the different content and control views. Layering those allows
@@ -501,10 +502,8 @@ void NotificationView::ButtonPressed(views::Button* sender,
// Show and hide subviews appropriately on expansion.
if (sender == expand_button()) {
- if (message_view_ && !item_views_.size() && !image_view_)
- message_view_->SetMaxLines(7);
- else if (message_view_ && item_views_.size())
- message_view_->SetVisible(false);
+ if (message_view_)
+ message_view_->SetVisible(!item_views_.size());
for (size_t i = 0; i < item_views_.size(); ++i)
item_views_[i]->SetVisible(true);
if (image_view_)
diff --git a/ui/message_center/views/notification_view.h b/ui/message_center/views/notification_view.h
index a0c5366..fb9adb7 100644
--- a/ui/message_center/views/notification_view.h
+++ b/ui/message_center/views/notification_view.h
@@ -9,9 +9,12 @@
#include "ui/message_center/views/message_view.h"
+namespace views {
+class Label;
+} // namespace views
+
namespace message_center {
-class BoundedLabel;
class NotificationChangeObserver;
// View that displays all current types of notification (web, basic, image, and
@@ -47,8 +50,8 @@ class NotificationView : public MessageView {
// Weak references to NotificationView descendants owned by their parents.
views::View* background_view_;
views::View* top_view_;
- BoundedLabel* title_view_;
- BoundedLabel* message_view_;
+ views::Label* title_view_;
+ views::Label* message_view_;
std::vector<views::View*> item_views_;
views::View* icon_view_;
views::View* bottom_view_;