Commit 71751aec authored by Kristyn Hamasaki's avatar Kristyn Hamasaki Committed by Commit Bot

Add metadata to TabStrip and convert properties

Bug: 982469
Change-Id: I7370d32d01e52e93814771666cab5c3500d809ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1693904
Commit-Queue: Kristyn Hamasaki <khamasaki@google.com>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676048}
parent d48c27ff
......@@ -121,8 +121,6 @@ class MdTabStrip : public TabStrip, public gfx::AnimationDelegate {
DISALLOW_COPY_AND_ASSIGN(MdTabStrip);
};
// static
const char Tab::kViewClassName[] = "Tab";
Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents)
: tabbed_pane_(tabbed_pane),
......@@ -272,10 +270,6 @@ gfx::Size Tab::CalculatePreferredSize() const {
return size;
}
const char* Tab::GetClassName() const {
return kViewClassName;
}
void Tab::SetState(State state) {
if (state == state_)
return;
......@@ -358,6 +352,10 @@ bool Tab::OnKeyPressed(const ui::KeyEvent& event) {
tabbed_pane_->MoveSelectionBy(key == ui::VKEY_DOWN ? 1 : -1);
}
BEGIN_METADATA(Tab)
METADATA_PARENT_CLASS(View)
END_METADATA()
MdTab::MdTab(TabbedPane* tabbed_pane,
const base::string16& title,
View* contents)
......@@ -428,7 +426,6 @@ void MdTab::OnBlur() {
// static
constexpr size_t TabStrip::kNoSelectedTab;
const char TabStrip::kViewClassName[] = "TabStrip";
TabStrip::TabStrip(TabbedPane::Orientation orientation,
TabbedPane::TabStripStyle style)
......@@ -459,10 +456,6 @@ TabStrip::~TabStrip() = default;
void TabStrip::OnSelectedTabChanged(Tab* from_tab, Tab* to_tab) {}
const char* TabStrip::GetClassName() const {
return kViewClassName;
}
void TabStrip::OnPaintBorder(gfx::Canvas* canvas) {
// Do not draw border line in kHighlight mode.
if (style_ == TabbedPane::TabStripStyle::kHighlight)
......@@ -558,6 +551,33 @@ Tab* TabStrip::GetTabAtDeltaFromSelected(int delta) const {
num_children);
}
TabbedPane::Orientation TabStrip::GetOrientation() const {
return orientation_;
}
TabbedPane::TabStripStyle TabStrip::GetStyle() const {
return style_;
}
DEFINE_ENUM_CONVERTERS(TabbedPane::Orientation,
{TabbedPane::Orientation::kHorizontal,
base::ASCIIToUTF16("HORIZONTAL")},
{TabbedPane::Orientation::kVertical,
base::ASCIIToUTF16("VERTICAL")})
DEFINE_ENUM_CONVERTERS(TabbedPane::TabStripStyle,
{TabbedPane::TabStripStyle::kBorder,
base::ASCIIToUTF16("BORDER")},
{TabbedPane::TabStripStyle::kHighlight,
base::ASCIIToUTF16("HIGHLIGHT")})
BEGIN_METADATA(TabStrip)
METADATA_PARENT_CLASS(View)
ADD_READONLY_PROPERTY_METADATA(TabStrip, int, SelectedTabIndex)
ADD_READONLY_PROPERTY_METADATA(TabStrip, TabbedPane::Orientation, Orientation)
ADD_READONLY_PROPERTY_METADATA(TabStrip, TabbedPane::TabStripStyle, Style)
END_METADATA()
MdTabStrip::MdTabStrip(TabbedPane::Orientation orientation,
TabbedPane::TabStripStyle style)
: TabStrip(orientation, style) {
......@@ -586,7 +606,7 @@ void MdTabStrip::OnSelectedTabChanged(Tab* from_tab, Tab* to_tab) {
DCHECK(!from_tab->selected());
DCHECK(to_tab->selected());
if (orientation() == TabbedPane::Orientation::kHorizontal) {
if (GetOrientation() == TabbedPane::Orientation::kHorizontal) {
animating_from_ = gfx::Range(from_tab->GetMirroredX(),
from_tab->GetMirroredX() + from_tab->width());
animating_to_ = gfx::Range(to_tab->GetMirroredX(),
......@@ -604,13 +624,13 @@ void MdTabStrip::OnSelectedTabChanged(Tab* from_tab, Tab* to_tab) {
void MdTabStrip::OnPaintBorder(gfx::Canvas* canvas) {
// Do not draw border line in kHighlight mode.
if (style() == TabbedPane::TabStripStyle::kHighlight)
if (GetStyle() == TabbedPane::TabStripStyle::kHighlight)
return;
constexpr int kUnselectedBorderThickness = 1;
constexpr int kSelectedBorderThickness = 2;
const bool is_horizontal =
orientation() == TabbedPane::Orientation::kHorizontal;
GetOrientation() == TabbedPane::Orientation::kHorizontal;
int max_cross_axis;
......@@ -785,11 +805,11 @@ gfx::Size TabbedPane::CalculatePreferredSize() const {
}
TabbedPane::Orientation TabbedPane::GetOrientation() const {
return tab_strip_->orientation();
return tab_strip_->GetOrientation();
}
TabbedPane::TabStripStyle TabbedPane::GetStyle() const {
return tab_strip_->style();
return tab_strip_->GetStyle();
}
Tab* TabbedPane::GetTabAt(size_t index) {
......
......@@ -143,8 +143,7 @@ class VIEWS_EXPORT TabbedPane : public View {
// The tab view shown in the tab strip.
class VIEWS_EXPORT Tab : public View {
public:
// Internal class name.
static const char kViewClassName[];
METADATA_HEADER(Tab);
Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents);
~Tab() override;
......@@ -163,7 +162,6 @@ class VIEWS_EXPORT Tab : public View {
void OnMouseExited(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
gfx::Size CalculatePreferredSize() const override;
const char* GetClassName() const override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
bool HandleAccessibleAction(const ui::AXActionData& action_data) override;
void OnFocus() override;
......@@ -203,12 +201,11 @@ class VIEWS_EXPORT Tab : public View {
// The tab strip shown above/left of the tab contents.
class TabStrip : public View {
public:
METADATA_HEADER(TabStrip);
// The return value of GetSelectedTabIndex() when no tab is selected.
static constexpr size_t kNoSelectedTab = size_t{-1};
// Internal class name.
static const char kViewClassName[];
TabStrip(TabbedPane::Orientation orientation,
TabbedPane::TabStripStyle style);
~TabStrip() override;
......@@ -219,7 +216,6 @@ class TabStrip : public View {
virtual void OnSelectedTabChanged(Tab* from_tab, Tab* to_tab);
// Overridden from View:
const char* GetClassName() const override;
void OnPaintBorder(gfx::Canvas* canvas) override;
Tab* GetSelectedTab() const;
......@@ -227,9 +223,9 @@ class TabStrip : public View {
Tab* GetTabAtIndex(size_t index) const;
size_t GetSelectedTabIndex() const;
TabbedPane::Orientation orientation() const { return orientation_; }
TabbedPane::Orientation GetOrientation() const;
TabbedPane::TabStripStyle style() const { return style_; }
TabbedPane::TabStripStyle GetStyle() const;
private:
// The orientation of the tab alignment.
......
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