Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/tabbed_pane/native_tabbed_pane_views.h" | 5 #include "ui/views/controls/tabbed_pane/native_tabbed_pane_views.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/font.h" | 11 #include "ui/gfx/font.h" |
| 12 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" | 12 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
| 13 #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h" | 13 #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h" |
| 14 #include "ui/views/layout/fill_layout.h" | 14 #include "ui/views/layout/fill_layout.h" |
| 15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 | 18 |
| 19 const SkColor kTabTitleColor_Inactive = SkColorSetRGB(0x66, 0x66, 0x66); | 19 const SkColor kTabTitleColor_Inactive = SkColorSetRGB(0x66, 0x66, 0x66); |
| 20 const SkColor kTabTitleColor_Active = SkColorSetRGB(0x20, 0x20, 0x20); | 20 const SkColor kTabTitleColor_Active = SkColorSetRGB(0x20, 0x20, 0x20); |
| 21 const SkColor kTabTitleColor_Pressed = SkColorSetRGB(0x33, 0x33, 0x33); | 21 const SkColor kTabTitleColor_Pressed = SkColorSetRGB(0x33, 0x33, 0x33); |
| 22 const SkColor kTabTitleColor_Hovered = SkColorSetRGB(0x22, 0x22, 0x22); | 22 const SkColor kTabTitleColor_Hovered = SkColorSetRGB(0x22, 0x22, 0x22); |
| 23 // TODO(markusheintz): The tab background color should be provided by the | 23 // TODO(markusheintz): The tab background color should be provided by the |
| 24 // NativeTheme. | 24 // NativeTheme. |
| 25 const SkColor kTabBackgroundColor_Active = SK_ColorWHITE; | 25 const SkColor kTabBackgroundColor_Active = SK_ColorWHITE; |
| 26 const SkColor kTabBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); | 26 const SkColor kTabBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); |
| 27 const SkScalar kTabBorderThickness = 1.0f; | 27 const SkScalar kTabBorderThickness = 1.0f; |
| 28 const SkScalar kTabBorderRadius = 2.0f; | 28 const SkScalar kTabBorderRadius = 2.0f; |
| 29 const SkColor kTabStripBackgroundColorStart = SK_ColorWHITE; | |
| 30 const SkColor kTabStripBackgroundColorEnd = SkColorSetRGB(0xEE, 0xEE, 0xEE); | |
| 29 | 31 |
| 30 class TabStrip; | 32 class TabStrip; |
| 31 | 33 |
| 32 class Tab : public View { | 34 class Tab : public View { |
| 33 public: | 35 public: |
| 34 Tab(TabStrip* tab_strip, const string16& title, View* contents) | 36 Tab(TabStrip* tab_strip, const string16& title, View* contents) |
| 35 : tab_strip_(tab_strip), | 37 : tab_strip_(tab_strip), |
| 36 title_(title), | 38 title_(title), |
| 37 contents_(contents), | 39 contents_(contents), |
| 38 title_color_(kTabTitleColor_Inactive) {} | 40 title_color_(kTabTitleColor_Inactive) {} |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 SkColor title_color_; | 119 SkColor title_color_; |
| 118 | 120 |
| 119 DISALLOW_COPY_AND_ASSIGN(Tab); | 121 DISALLOW_COPY_AND_ASSIGN(Tab); |
| 120 }; | 122 }; |
| 121 | 123 |
| 122 class TabStrip : public View { | 124 class TabStrip : public View { |
| 123 public: | 125 public: |
| 124 explicit TabStrip(NativeTabbedPaneViews* owner) | 126 explicit TabStrip(NativeTabbedPaneViews* owner) |
| 125 : owner_(owner), | 127 : owner_(owner), |
| 126 selected_tab_(NULL) { | 128 selected_tab_(NULL) { |
| 129 const float gradient_start = 0.7f; | |
|
msw
2012/08/08 17:12:20
nit: please compare snapshots or get values from U
msw
2012/08/08 18:29:50
nit: i think this needs const naming kGradientStar
markusheintz_
2012/08/08 21:53:55
It's a bit tricky because the shadows around the t
markusheintz_
2012/08/08 21:53:55
obsolete.
| |
| 130 const float gradient_end = 1.0f; | |
| 131 set_background(Background::CreateVerticalGradientRangeBackground( | |
| 132 kTabStripBackgroundColorStart, kTabStripBackgroundColorEnd, | |
| 133 gradient_start, gradient_end)); | |
| 127 } | 134 } |
| 128 virtual ~TabStrip() {} | 135 virtual ~TabStrip() {} |
| 129 | 136 |
| 130 void SelectTab(View* tab) { | 137 void SelectTab(View* tab) { |
| 131 if (tab == selected_tab_) | 138 if (tab == selected_tab_) |
| 132 return; | 139 return; |
| 133 if (selected_tab_) | 140 if (selected_tab_) |
| 134 static_cast<Tab*>(selected_tab_)->OnSelectedStateChanged(false); | 141 static_cast<Tab*>(selected_tab_)->OnSelectedStateChanged(false); |
| 135 selected_tab_ = tab; | 142 selected_tab_ = tab; |
| 136 static_cast<Tab*>(selected_tab_)->OnSelectedStateChanged(true); | 143 static_cast<Tab*>(selected_tab_)->OnSelectedStateChanged(true); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 161 const int kTabOffset = 18; | 168 const int kTabOffset = 18; |
| 162 int x = kTabOffset; // Layout tabs with an offset to the tabstrip border. | 169 int x = kTabOffset; // Layout tabs with an offset to the tabstrip border. |
| 163 for (int i = 0; i < child_count(); ++i) { | 170 for (int i = 0; i < child_count(); ++i) { |
| 164 gfx::Size ps = child_at(i)->GetPreferredSize(); | 171 gfx::Size ps = child_at(i)->GetPreferredSize(); |
| 165 child_at(i)->SetBounds(x, 0, ps.width(), ps.height()); | 172 child_at(i)->SetBounds(x, 0, ps.width(), ps.height()); |
| 166 x = child_at(i)->bounds().right(); | 173 x = child_at(i)->bounds().right(); |
| 167 } | 174 } |
| 168 } | 175 } |
| 169 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 176 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 170 SkPaint paint; | 177 SkPaint paint; |
| 178 OnPaintBackground(canvas); | |
|
msw
2012/08/08 17:12:20
Perhaps just call View::OnPaint here (or above the
markusheintz_
2012/08/08 21:53:55
Moved above the SkPaint.
I deliberately didn't ca
| |
| 171 paint.setColor(kTabBorderColor); | 179 paint.setColor(kTabBorderColor); |
| 172 paint.setStrokeWidth(kTabBorderThickness); | 180 paint.setStrokeWidth(kTabBorderThickness); |
| 173 SkScalar line_y = SkIntToScalar(height()) - kTabBorderThickness; | 181 SkScalar line_y = SkIntToScalar(height()) - kTabBorderThickness; |
| 174 SkScalar line_width = SkIntToScalar(width()); | 182 SkScalar line_width = SkIntToScalar(width()); |
| 175 canvas->sk_canvas()->drawLine(0, line_y, line_width, line_y, paint); | 183 canvas->sk_canvas()->drawLine(0, line_y, line_width, line_y, paint); |
| 176 } | 184 } |
| 177 | 185 |
| 178 private: | 186 private: |
| 179 NativeTabbedPaneViews* owner_; | 187 NativeTabbedPaneViews* owner_; |
| 180 View* selected_tab_; | 188 View* selected_tab_; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 if (tab_strip_->has_children()) | 410 if (tab_strip_->has_children()) |
| 403 InitializeTabs(); | 411 InitializeTabs(); |
| 404 } | 412 } |
| 405 | 413 |
| 406 void NativeTabbedPaneViews::InitializeTabs() { | 414 void NativeTabbedPaneViews::InitializeTabs() { |
| 407 for (int i = 0; i < tab_strip_->child_count(); ++i) | 415 for (int i = 0; i < tab_strip_->child_count(); ++i) |
| 408 content_view_->AddChildView(Tab::GetContents(tab_strip_->child_at(i))); | 416 content_view_->AddChildView(Tab::GetContents(tab_strip_->child_at(i))); |
| 409 } | 417 } |
| 410 | 418 |
| 411 } // namespace views | 419 } // namespace views |
| OLD | NEW |