Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: chrome/browser/views/tabs/tab_2.cc

Issue 42490: Experiments with a new tabstrip + animator (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/views/tabs/tab_2.h ('k') | chrome/browser/views/tabs/tab_strip_2.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file.
4
5 #include "chrome/browser/views/tabs/tab_2.h"
6
7 #include "app/gfx/canvas.h"
8 #include "app/gfx/font.h"
9 #include "app/gfx/path.h"
10 #include "views/animator.h"
11
12 static const SkScalar kTabCapWidth = 15;
13 static const SkScalar kTabTopCurveWidth = 4;
14 static const SkScalar kTabBottomCurveWidth = 3;
15
16 ////////////////////////////////////////////////////////////////////////////////
17 // Tab2, public:
18
19 Tab2::Tab2(Tab2Model* model)
20 : model_(model),
21 dragging_(false),
22 removing_(false) {
23 }
24
25 Tab2::~Tab2() {
26 }
27
28 void Tab2::SetRemovingModel(Tab2Model* model) {
29 removing_model_.reset(model);
30 model_ = removing_model_.get();
31 }
32
33 bool Tab2::IsAnimating() const {
34 return animator_.get() && animator_->IsAnimating();
35 }
36
37 views::Animator* Tab2::GetAnimator() {
38 if (!animator_.get())
39 animator_.reset(new views::Animator(this, model_->AsAnimatorDelegate()));
40 return animator_.get();
41 }
42
43 // static
44 gfx::Size Tab2::GetStandardSize() {
45 return gfx::Size(140, 27);
46 }
47
48 void Tab2::AddTabShapeToPath(gfx::Path* path) const {
49 SkScalar h = SkIntToScalar(height());
50 SkScalar w = SkIntToScalar(width());
51
52 path->moveTo(0, h);
53
54 // Left end cap.
55 path->lineTo(kTabBottomCurveWidth, h - kTabBottomCurveWidth);
56 path->lineTo(kTabCapWidth - kTabTopCurveWidth, kTabTopCurveWidth);
57 path->lineTo(kTabCapWidth, 0);
58
59 // Connect to the right cap.
60 path->lineTo(w - kTabCapWidth, 0);
61
62 // Right end cap.
63 path->lineTo(w - kTabCapWidth + kTabTopCurveWidth, kTabTopCurveWidth);
64 path->lineTo(w - kTabBottomCurveWidth, h - kTabBottomCurveWidth);
65 path->lineTo(w, h);
66
67 // Close out the path.
68 path->lineTo(0, h);
69 path->close();
70 }
71
72 ////////////////////////////////////////////////////////////////////////////////
73 // Tab2, views::View overrides:
74
75 gfx::Size Tab2::GetPreferredSize() {
76 return gfx::Size();
77 }
78
79 void Tab2::Layout() {
80 }
81
82 void Tab2::Paint(gfx::Canvas* canvas) {
83 SkColor color = model_->IsSelected(this) ? SK_ColorRED : SK_ColorGREEN;
84
85 gfx::Path path;
86 AddTabShapeToPath(&path);
87 SkPaint paint;
88 paint.setAntiAlias(true);
89 paint.setColor(color);
90 canvas->drawPath(path, paint);
91
92 // TODO(beng): less ad-hoc
93 canvas->DrawStringInt(model_->GetTitle(this), gfx::Font(), SK_ColorBLACK,
94 5, 3, 100, 20);
95 }
96
97 bool Tab2::OnMousePressed(const views::MouseEvent& event) {
98 if (event.IsLeftMouseButton()) {
99 model_->SelectTab(this);
100 model_->CaptureDragInfo(this, event);
101 }
102 return true;
103 }
104
105 bool Tab2::OnMouseDragged(const views::MouseEvent& event) {
106 dragging_ = true;
107 return model_->DragTab(this, event);
108 }
109
110 void Tab2::OnMouseReleased(const views::MouseEvent& event, bool canceled) {
111 if (dragging_) {
112 dragging_ = false;
113 model_->DragEnded(this);
114 }
115 }
116
117 void Tab2::DidChangeBounds(const gfx::Rect& previous,
118 const gfx::Rect& current) {
119 }
OLDNEW
« no previous file with comments | « chrome/browser/views/tabs/tab_2.h ('k') | chrome/browser/views/tabs/tab_strip_2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698