Commit 54d3e0e0 authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

Convert enum to enum class for Tab::TabState

Use enum class instead of enum for Tab::TabState
enum class is more type safety.

Bug: 940736
Change-Id: I8ad3e087727934c176f3a50ae55d54755590fe39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1546736
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650944}
parent 93c0d514
......@@ -130,7 +130,7 @@ const char Tab::kViewClassName[] = "Tab";
Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents)
: tabbed_pane_(tabbed_pane),
title_(new Label(title, style::CONTEXT_LABEL, style::STYLE_TAB_ACTIVE)),
tab_state_(TAB_ACTIVE),
state_(State::kActive),
contents_(contents) {
// Calculate the size while the font list is bold.
preferred_title_size_ = title_->GetPreferredSize();
......@@ -154,7 +154,7 @@ Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents)
gfx::Insets(kTabVerticalPadding, kTabHorizontalPadding)));
}
SetLayoutManager(std::make_unique<FillLayout>());
SetState(TAB_INACTIVE);
SetState(State::kInactive);
// Calculate the size while the font list is normal and set the max size.
preferred_title_size_.SetToMax(title_->GetPreferredSize());
AddChildView(title_);
......@@ -168,7 +168,7 @@ Tab::~Tab() = default;
void Tab::SetSelected(bool selected) {
contents_->SetVisible(selected);
SetState(selected ? TAB_ACTIVE : TAB_INACTIVE);
SetState(selected ? State::kActive : State::kInactive);
#if defined(OS_MACOSX)
SetFocusBehavior(selected ? FocusBehavior::ACCESSIBLE_ONLY
: FocusBehavior::NEVER);
......@@ -183,8 +183,8 @@ void Tab::OnStateChanged() {
tabbed_pane_->GetStyle() == TabbedPane::TabStripStyle::kHighlight;
const int font_size_delta = is_highlight_mode ? kLabelFontSizeDeltaHighlight
: ui::kLabelFontSizeDelta;
switch (tab_state_) {
case TAB_INACTIVE:
switch (state_) {
case State::kInactive:
// Notify assistive tools to update this tab's selected status.
// The way Chrome OS accessibility is implemented right now, firing almost
// any event will work, we just need to trigger its state to be refreshed.
......@@ -197,13 +197,13 @@ void Tab::OnStateChanged() {
is_highlight_mode ? kInactiveWeightHighlight
: kInactiveWeightBorder));
break;
case TAB_ACTIVE:
case State::kActive:
title_->SetEnabledColor(is_highlight_mode ? kTabTitleColor_ActiveHighlight
: kTabTitleColor_ActiveBorder);
title_->SetFontList(rb.GetFontListWithDelta(
font_size_delta, gfx::Font::NORMAL, kActiveWeight));
break;
case TAB_HOVERED:
case State::kHovered:
title_->SetEnabledColor(kTabTitleColor_Hovered);
title_->SetFontList(rb.GetFontListWithDelta(
font_size_delta, gfx::Font::NORMAL,
......@@ -219,11 +219,11 @@ bool Tab::OnMousePressed(const ui::MouseEvent& event) {
}
void Tab::OnMouseEntered(const ui::MouseEvent& event) {
SetState(selected() ? TAB_ACTIVE : TAB_HOVERED);
SetState(selected() ? State::kActive : State::kHovered);
}
void Tab::OnMouseExited(const ui::MouseEvent& event) {
SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE);
SetState(selected() ? State::kActive : State::kInactive);
}
void Tab::OnGestureEvent(ui::GestureEvent* event) {
......@@ -235,7 +235,7 @@ void Tab::OnGestureEvent(ui::GestureEvent* event) {
tabbed_pane_->SelectTab(this);
break;
case ui::ET_GESTURE_TAP_CANCEL:
SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE);
SetState(selected() ? State::kActive : State::kInactive);
break;
default:
break;
......@@ -258,10 +258,10 @@ const char* Tab::GetClassName() const {
return kViewClassName;
}
void Tab::SetState(TabState tab_state) {
if (tab_state == tab_state_)
void Tab::SetState(State state) {
if (state == state_)
return;
tab_state_ = tab_state;
state_ = state;
OnStateChanged();
SchedulePaint();
}
......
......@@ -152,17 +152,17 @@ class Tab : public View {
TabbedPane* tabbed_pane() { return tabbed_pane_; }
// Called whenever |tab_state_| changes.
// Called whenever |state_| changes.
virtual void OnStateChanged();
private:
enum TabState {
TAB_INACTIVE,
TAB_ACTIVE,
TAB_HOVERED,
enum class State {
kInactive,
kActive,
kHovered,
};
void SetState(TabState tab_state);
void SetState(State state);
// views::View:
void OnPaint(gfx::Canvas* canvas) override;
......@@ -170,7 +170,7 @@ class Tab : public View {
TabbedPane* tabbed_pane_;
Label* title_;
gfx::Size preferred_title_size_;
TabState tab_state_;
State state_;
// The content view associated with this tab.
View* contents_;
......
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