Commit 406c22f3 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Clean up TabbedPane.

Tab and TabStrip are only ever instantiated as MdTab and MdTabStrip.  Combine
the code for the subclasses with the parents, eliminating unreachable code.

Inline various constants that are only used once and whose names added no
real clarity.  Rewrite a few places for brevity.  Reorder definitions to
match declarations.

Bug: 934273
Change-Id: I7853a96d0929e8eeedc60f421b8426e171befec7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1809632
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697619}
parent 0656b286
......@@ -10,6 +10,8 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/views/view.h"
namespace views {
......@@ -168,14 +170,6 @@ class VIEWS_EXPORT Tab : public View {
void OnBlur() override;
bool OnKeyPressed(const ui::KeyEvent& event) override;
protected:
Label* title() { return title_; }
TabbedPane* tabbed_pane() { return tabbed_pane_; }
// Called whenever |state_| changes.
virtual void OnStateChanged();
private:
enum class State {
kInactive,
......@@ -185,13 +179,16 @@ class VIEWS_EXPORT Tab : public View {
void SetState(State state);
// Called whenever |state_| changes.
void OnStateChanged();
// views::View:
void OnPaint(gfx::Canvas* canvas) override;
TabbedPane* tabbed_pane_;
Label* title_ = nullptr;
gfx::Size preferred_title_size_;
State state_;
int preferred_title_width_;
State state_ = State::kActive;
// The content view associated with this tab.
View* contents_;
......@@ -199,7 +196,7 @@ class VIEWS_EXPORT Tab : public View {
};
// The tab strip shown above/left of the tab contents.
class TabStrip : public View {
class TabStrip : public View, public gfx::AnimationDelegate {
public:
METADATA_HEADER(TabStrip);
......@@ -210,13 +207,17 @@ class TabStrip : public View {
TabbedPane::TabStripStyle style);
~TabStrip() override;
// Overridden from View:
void OnPaintBorder(gfx::Canvas* canvas) override;
// Overridden from AnimationDelegate:
void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationEnded(const gfx::Animation* animation) override;
// Called by TabStrip when the selected tab changes. This function is only
// called if |from_tab| is not null, i.e., there was a previously selected
// tab.
virtual void OnSelectedTabChanged(Tab* from_tab, Tab* to_tab);
// Overridden from View:
void OnPaintBorder(gfx::Canvas* canvas) override;
void OnSelectedTabChanged(Tab* from_tab, Tab* to_tab);
Tab* GetSelectedTab() const;
Tab* GetTabAtDeltaFromSelected(int delta) const;
......@@ -234,6 +235,20 @@ class TabStrip : public View {
// The style of the tab strip.
const TabbedPane::TabStripStyle style_;
// Animations for expanding and contracting the selection bar. When changing
// selections, the selection bar first grows to encompass both the old and new
// selections, then shrinks to encompass only the new selection. The rates of
// expansion and contraction each follow the cubic bezier curves used in
// gfx::Tween; see TabStrip::OnPaintBorder for details.
std::unique_ptr<gfx::LinearAnimation> expand_animation_ =
std::make_unique<gfx::LinearAnimation>(this);
std::unique_ptr<gfx::LinearAnimation> contract_animation_ =
std::make_unique<gfx::LinearAnimation>(this);
// The x-coordinate ranges of the old selection and the new selection.
gfx::Range animating_from_;
gfx::Range animating_to_;
DISALLOW_COPY_AND_ASSIGN(TabStrip);
};
......
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