Commit 00bdb2d5 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Make InfoBarView access for overrides match parents.

This is recommended team practice now, and will help with a unittest that wants
to call InfoBarView::Layout().

No functional changes.

BUG=834728
TEST=none
TBR=estade

Change-Id: Id8745264363e62e8becb5f9b8aa6071d6e6234bd
Reviewed-on: https://chromium-review.googlesource.com/1019364Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552245}
parent e88248f6
......@@ -143,29 +143,6 @@ void InfoBarView::RecalculateHeight() {
SetTargetHeight(height + GetSeparatorHeightDip());
}
views::Label* InfoBarView::CreateLabel(const base::string16& text) const {
views::Label* label = new views::Label(text, CONTEXT_BODY_TEXT_LARGE);
SetLabelDetails(label);
label->SetEnabledColor(GetColor(kTextColor));
label->SetProperty(kLabelType, LabelType::kLabel);
return label;
}
views::Link* InfoBarView::CreateLink(const base::string16& text,
views::LinkListener* listener) const {
views::Link* link = new views::Link(text, CONTEXT_BODY_TEXT_LARGE);
SetLabelDetails(link);
link->set_listener(listener);
link->SetProperty(kLabelType, LabelType::kLink);
return link;
}
// static
void InfoBarView::AssignWidths(Labels* labels, int available_width) {
std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth);
AssignWidthsSorted(labels, available_width);
}
void InfoBarView::Layout() {
const int spacing = GetElementSpacing();
int start_x = 0;
......@@ -190,6 +167,29 @@ void InfoBarView::Layout() {
close_button_->parent()->GetIndexOf(close_button_));
}
void InfoBarView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetName(l10n_util::GetStringUTF8(IDS_ACCNAME_INFOBAR));
node_data->role = ax::mojom::Role::kAlert;
node_data->AddStringAttribute(ax::mojom::StringAttribute::kKeyShortcuts,
"Alt+Shift+A");
}
gfx::Size InfoBarView::CalculatePreferredSize() const {
int width = 0;
const int spacing = GetElementSpacing();
if (icon_)
width += spacing + icon_->width();
const int content_width = ContentMinimumWidth();
if (content_width)
width += spacing + content_width;
return gfx::Size(
width + GetCloseButtonSpacing().width() + close_button_->width(),
computed_height());
}
void InfoBarView::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
View::ViewHierarchyChanged(details);
......@@ -251,6 +251,40 @@ void InfoBarView::ButtonPressed(views::Button* sender,
}
}
void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) {
views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now);
// This will trigger some screen readers to read the entire contents of this
// infobar.
if (focused_before && focused_now && !Contains(focused_before) &&
Contains(focused_now)) {
NotifyAccessibilityEvent(ax::mojom::Event::kAlert, true);
}
}
views::Label* InfoBarView::CreateLabel(const base::string16& text) const {
views::Label* label = new views::Label(text, CONTEXT_BODY_TEXT_LARGE);
SetLabelDetails(label);
label->SetEnabledColor(GetColor(kTextColor));
label->SetProperty(kLabelType, LabelType::kLabel);
return label;
}
views::Link* InfoBarView::CreateLink(const base::string16& text,
views::LinkListener* listener) const {
views::Link* link = new views::Link(text, CONTEXT_BODY_TEXT_LARGE);
SetLabelDetails(link);
link->set_listener(listener);
link->SetProperty(kLabelType, LabelType::kLink);
return link;
}
// static
void InfoBarView::AssignWidths(Labels* labels, int available_width) {
std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth);
AssignWidthsSorted(labels, available_width);
}
int InfoBarView::ContentMinimumWidth() const {
return 0;
}
......@@ -273,19 +307,6 @@ int InfoBarView::OffsetY(views::View* view) const {
(target_height() - height());
}
// static
void InfoBarView::AssignWidthsSorted(Labels* labels, int available_width) {
if (labels->empty())
return;
gfx::Size back_label_size(labels->back()->GetPreferredSize());
back_label_size.set_width(
std::min(back_label_size.width(),
available_width / static_cast<int>(labels->size())));
labels->back()->SetSize(back_label_size);
labels->pop_back();
AssignWidthsSorted(labels, available_width - back_label_size.width());
}
void InfoBarView::PlatformSpecificShow(bool animate) {
// If we gain focus, we want to restore it to the previously-focused element
// when we're hidden. So when we're in a Widget, create a focus tracker so
......@@ -322,38 +343,17 @@ void InfoBarView::PlatformSpecificOnHeightRecalculated() {
InvalidateLayout();
}
void InfoBarView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetName(l10n_util::GetStringUTF8(IDS_ACCNAME_INFOBAR));
node_data->role = ax::mojom::Role::kAlert;
node_data->AddStringAttribute(ax::mojom::StringAttribute::kKeyShortcuts,
"Alt+Shift+A");
}
gfx::Size InfoBarView::CalculatePreferredSize() const {
int width = 0;
const int spacing = GetElementSpacing();
if (icon_)
width += spacing + icon_->width();
const int content_width = ContentMinimumWidth();
if (content_width)
width += spacing + content_width;
return gfx::Size(
width + GetCloseButtonSpacing().width() + close_button_->width(),
computed_height());
}
void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) {
views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now);
// This will trigger some screen readers to read the entire contents of this
// infobar.
if (focused_before && focused_now && !Contains(focused_before) &&
Contains(focused_now)) {
NotifyAccessibilityEvent(ax::mojom::Event::kAlert, true);
}
// static
void InfoBarView::AssignWidthsSorted(Labels* labels, int available_width) {
if (labels->empty())
return;
gfx::Size back_label_size(labels->back()->GetPreferredSize());
back_label_size.set_width(
std::min(back_label_size.width(),
available_width / static_cast<int>(labels->size())));
labels->back()->SetSize(back_label_size);
labels->pop_back();
AssignWidthsSorted(labels, available_width - back_label_size.width());
}
bool InfoBarView::ShouldDrawSeparator() const {
......
......@@ -34,6 +34,24 @@ class InfoBarView : public infobars::InfoBar,
// Requests that the infobar recompute its target height.
void RecalculateHeight();
// views::View:
void Layout() override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
gfx::Size CalculatePreferredSize() const override;
void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) override;
void OnPaint(gfx::Canvas* canvas) override;
void OnThemeChanged() override;
void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
// views::ButtonListener:
// NOTE: This must not be called if we're unowned. (Subclasses should ignore
// calls to ButtonPressed() in this case.)
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::ExternalFocusTracker:
void OnWillChangeFocus(View* focused_before, View* focused_now) override;
protected:
using Labels = std::vector<views::Label*>;
......@@ -51,19 +69,6 @@ class InfoBarView : public infobars::InfoBar,
// length of the next-longest, and so forth.
static void AssignWidths(Labels* labels, int available_width);
// views::View:
void Layout() override;
void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) override;
void OnPaint(gfx::Canvas* canvas) override;
void OnThemeChanged() override;
void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
// views::ButtonListener:
// NOTE: This must not be called if we're unowned. (Subclasses should ignore
// calls to ButtonPressed() in this case.)
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Returns the minimum width the content (that is, everything between the icon
// and the close button) can be shrunk to. This is used to prevent the close
// button from overlapping views that cannot be shrunk any further.
......@@ -79,6 +84,11 @@ class InfoBarView : public infobars::InfoBar,
// closed.
int OffsetY(views::View* view) const;
// infobars::InfoBar:
void PlatformSpecificShow(bool animate) override;
void PlatformSpecificHide(bool animate) override;
void PlatformSpecificOnHeightRecalculated() override;
private:
FRIEND_TEST_ALL_PREFIXES(InfoBarViewTest, ShouldDrawSeparator);
......@@ -86,18 +96,6 @@ class InfoBarView : public infobars::InfoBar,
// decreasing preferred width.
static void AssignWidthsSorted(Labels* labels, int available_width);
// InfoBar:
void PlatformSpecificShow(bool animate) override;
void PlatformSpecificHide(bool animate) override;
void PlatformSpecificOnHeightRecalculated() override;
// views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
gfx::Size CalculatePreferredSize() const override;
// views::ExternalFocusTracker:
void OnWillChangeFocus(View* focused_before, View* focused_now) override;
// Returns whether this infobar should draw a 1 px separator at its top.
bool ShouldDrawSeparator() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment