#include "grit/ui_resources.h"
#include "grit/ui_strings.h"
#include "ui/base/cursor/cursor.h"
-#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
-#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/size.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/native_cursor.h"
#include "ui/views/painter.h"
+#include "ui/views/view_targeter.h"
#include "ui/views/widget/widget.h"
namespace {
return notification_view;
}
+views::View* NotificationView::TargetForRect(views::View* root,
+ const gfx::Rect& rect) {
+ CHECK_EQ(root, this);
+
+ // TODO(tdanderson): Modify this function to support rect-based event
+ // targeting. Using the center point of |rect| preserves this function's
+ // expected behavior for the time being.
+ gfx::Point point = rect.CenterPoint();
+
+ // Want to return this for underlying views, otherwise GetCursor is not
+ // called. But buttons are exceptions, they'll have their own event handlings.
+ std::vector<views::View*> buttons(action_buttons_.begin(),
+ action_buttons_.end());
+ buttons.push_back(close_button());
+
+ for (size_t i = 0; i < buttons.size(); ++i) {
+ gfx::Point point_in_child = point;
+ ConvertPointToTarget(this, buttons[i], &point_in_child);
+ if (buttons[i]->HitTestPoint(point_in_child))
+ return buttons[i]->GetEventHandlerForPoint(point_in_child);
+ }
+
+ return root;
+}
+
void NotificationView::CreateOrUpdateViews(const Notification& notification) {
CreateOrUpdateTitleView(notification);
CreateOrUpdateMessageView(notification);
AddChildView(small_image());
AddChildView(close_button());
SetAccessibleName(notification);
+
+ SetEventTargeter(
+ scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
}
NotificationView::~NotificationView() {
views::View::ScrollRectToVisible(GetLocalBounds());
}
-views::View* NotificationView::GetEventHandlerForRect(const gfx::Rect& rect) {
- // TODO(tdanderson): Modify this function to support rect-based event
- // targeting. Using the center point of |rect| preserves this function's
- // expected behavior for the time being.
- gfx::Point point = rect.CenterPoint();
-
- // Want to return this for underlying views, otherwise GetCursor is not
- // called. But buttons are exceptions, they'll have their own event handlings.
- std::vector<views::View*> buttons(action_buttons_.begin(),
- action_buttons_.end());
- buttons.push_back(close_button());
-
- for (size_t i = 0; i < buttons.size(); ++i) {
- gfx::Point point_in_child = point;
- ConvertPointToTarget(this, buttons[i], &point_in_child);
- if (buttons[i]->HitTestPoint(point_in_child))
- return buttons[i]->GetEventHandlerForPoint(point_in_child);
- }
-
- return this;
-}
-
gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) {
if (!clickable_ || !controller_->HasClickedListener(notification_id()))
return views::View::GetCursor(event);
int title_character_limit =
kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter;
+ base::string16 title = gfx::TruncateString(notification.title(),
+ title_character_limit,
+ gfx::WORD_BREAK);
if (!title_view_) {
int padding = kTitleLineHeight - font_list.GetHeight();
- title_view_ = new BoundedLabel(
- gfx::TruncateString(notification.title(), title_character_limit),
- font_list);
+ title_view_ = new BoundedLabel(title, font_list);
title_view_->SetLineHeight(kTitleLineHeight);
title_view_->SetLineLimit(kMaxTitleLines);
title_view_->SetColors(message_center::kRegularTextColor,
title_view_->SetBorder(MakeTextBorder(padding, 3, 0));
top_view_->AddChildView(title_view_);
} else {
- title_view_->SetText(
- gfx::TruncateString(notification.title(), title_character_limit));
+ title_view_->SetText(title);
}
}
DCHECK(top_view_ != NULL);
+ base::string16 text = gfx::TruncateString(notification.message(),
+ kMessageCharacterLimit,
+ gfx::WORD_BREAK);
if (!message_view_) {
int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
- message_view_ = new BoundedLabel(
- gfx::TruncateString(notification.message(), kMessageCharacterLimit));
+ message_view_ = new BoundedLabel(text);
message_view_->SetLineHeight(kMessageLineHeight);
message_view_->SetColors(message_center::kRegularTextColor,
kDimTextBackgroundColor);
message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
top_view_->AddChildView(message_view_);
} else {
- message_view_->SetText(
- gfx::TruncateString(notification.message(), kMessageCharacterLimit));
+ message_view_->SetText(text);
}
message_view_->SetVisible(!notification.items().size());
DCHECK(top_view_ != NULL);
+ base::string16 text = gfx::TruncateString(notification.context_message(),
+ kContextMessageCharacterLimit,
+ gfx::WORD_BREAK);
if (!context_message_view_) {
int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
- context_message_view_ = new BoundedLabel(gfx::TruncateString(
- notification.context_message(), kContextMessageCharacterLimit));
+ context_message_view_ = new BoundedLabel(text);
context_message_view_->SetLineLimit(
message_center::kContextMessageLineLimit);
context_message_view_->SetLineHeight(kMessageLineHeight);
context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
top_view_->AddChildView(context_message_view_);
} else {
- context_message_view_->SetText(gfx::TruncateString(
- notification.context_message(), kContextMessageCharacterLimit));
+ context_message_view_->SetText(text);
}
}