| 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 namespace { |
| 20 const SkColor kTabTitleColor_Active = SkColorSetRGB(0x20, 0x20, 0x20); | 20 struct TabColors { |
| 21 const SkColor kTabTitleColor_Pressed = SkColorSetRGB(0x33, 0x33, 0x33); | 21 SkColor title_inactive; |
| 22 const SkColor kTabTitleColor_Hovered = SkColorSetRGB(0x22, 0x22, 0x22); | 22 SkColor title_active; |
| 23 SkColor title_pressed; |
| 24 SkColor title_hovered; |
| 25 |
| 26 SkColor border; |
| 27 }; |
| 28 |
| 29 TabColors standard_colors = { |
| 30 SkColorSetRGB(0x66, 0x66, 0x66), |
| 31 SkColorSetRGB(0x20, 0x20, 0x20), |
| 32 SkColorSetRGB(0x33, 0x33, 0x33), |
| 33 SkColorSetRGB(0x22, 0x22, 0x22), |
| 34 |
| 35 SkColorSetRGB(0xCC, 0xCC, 0xCC) |
| 36 }; |
| 37 |
| 38 TabColors chrome_style_colors = { |
| 39 SkColorSetRGB(0x64, 0x64, 0x64), |
| 40 SkColorSetRGB(0x00, 0x00, 0x00), |
| 41 SkColorSetRGB(0x00, 0x00, 0x00), |
| 42 SkColorSetRGB(0x00, 0x00, 0x00), |
| 43 |
| 44 SkColorSetRGB(0xC8, 0xC8, 0xC8) |
| 45 }; |
| 46 } // namespace |
| 47 |
| 23 // TODO(markusheintz): The tab background color should be provided by the | 48 // TODO(markusheintz): The tab background color should be provided by the |
| 24 // NativeTheme. | 49 // NativeTheme. |
| 25 const SkColor kTabBackgroundColor_Active = SK_ColorWHITE; | 50 const SkColor kTabBackgroundColor_Active = SK_ColorWHITE; |
| 26 const SkColor kTabBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); | |
| 27 const SkScalar kTabBorderThickness = 1.0f; | 51 const SkScalar kTabBorderThickness = 1.0f; |
| 28 const SkScalar kTabBorderRadius = 2.0f; | 52 const SkScalar kTabBorderRadius = 2.0f; |
| 29 | 53 |
| 30 class TabStrip; | 54 class TabStrip; |
| 31 | 55 |
| 32 class Tab : public View { | 56 class Tab : public View { |
| 33 public: | 57 public: |
| 34 Tab(TabStrip* tab_strip, const string16& title, View* contents) | 58 Tab(TabStrip* tab_strip, |
| 59 const string16& title, |
| 60 View* contents, |
| 61 bool use_chrome_style) |
| 35 : tab_strip_(tab_strip), | 62 : tab_strip_(tab_strip), |
| 36 title_(title), | 63 title_(title), |
| 37 contents_(contents), | 64 contents_(contents), |
| 38 title_color_(kTabTitleColor_Inactive) {} | 65 use_chrome_style_(use_chrome_style), |
| 66 tab_colors_(use_chrome_style ? chrome_style_colors : standard_colors), |
| 67 title_color_(tab_colors_.title_inactive) {} |
| 39 virtual ~Tab() {} | 68 virtual ~Tab() {} |
| 40 | 69 |
| 41 static int GetMinimumTabHeight() { | 70 static int GetMinimumTabHeight() { |
| 42 return gfx::Font().GetHeight() + 10; | 71 return gfx::Font().GetHeight() + 10; |
| 43 } | 72 } |
| 44 | 73 |
| 45 static View* GetContents(View* tab) { | 74 static View* GetContents(View* tab) { |
| 46 return static_cast<Tab*>(tab)->contents_; | 75 return static_cast<Tab*>(tab)->contents_; |
| 47 } | 76 } |
| 48 | 77 |
| 49 void OnSelectedStateChanged(bool selected); | 78 void OnSelectedStateChanged(bool selected); |
| 50 | 79 |
| 51 // Overridden from View: | 80 // Overridden from View: |
| 52 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 81 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 53 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 82 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
| 54 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 83 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
| 55 virtual void OnMouseCaptureLost() OVERRIDE; | 84 virtual void OnMouseCaptureLost() OVERRIDE; |
| 56 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 85 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
| 57 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 86 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
| 58 virtual gfx::Size GetPreferredSize() OVERRIDE { | 87 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 59 const int kTabMinWidth = 54; | 88 const int kTabMinWidth = 54; |
| 60 gfx::Size ps(GetTabTitleFont().GetStringWidth(title_), | 89 gfx::Size ps(GetTabTitleFont(true).GetStringWidth(title_), |
| 61 GetMinimumTabHeight()); | 90 GetMinimumTabHeight()); |
| 62 ps.Enlarge(30, 10); | 91 ps.Enlarge(use_chrome_style_ ? 20 : 30, 10); |
| 63 if (ps.width() < kTabMinWidth) | 92 if (ps.width() < kTabMinWidth) |
| 64 ps.set_width(kTabMinWidth); | 93 ps.set_width(kTabMinWidth); |
| 65 return ps; | 94 return ps; |
| 66 } | 95 } |
| 67 | 96 |
| 68 private: | 97 private: |
| 69 void PaintTabBackground(gfx::Canvas* canvas) { | 98 void PaintTabBackground(gfx::Canvas* canvas) { |
| 70 // Fill the background. Note that we don't constrain to the bounds as | 99 // Fill the background. Note that we don't constrain to the bounds as |
| 71 // canvas is already clipped for us. | 100 // canvas is already clipped for us. |
| 72 canvas->DrawColor(kTabBackgroundColor_Active); | 101 canvas->DrawColor(kTabBackgroundColor_Active); |
| 73 } | 102 } |
| 74 | 103 |
| 75 void PaintTabBorder(gfx::Canvas* canvas) { | 104 void PaintTabBorder(gfx::Canvas* canvas) { |
| 76 SkPath path; | 105 SkPath path; |
| 77 SkRect bounds = { 0, 0, SkIntToScalar(width()), SkIntToScalar(height()) }; | 106 SkRect bounds = { 0, 0, SkIntToScalar(width()), SkIntToScalar(height()) }; |
| 78 SkScalar radii[8] = { kTabBorderRadius, kTabBorderRadius, | 107 SkScalar radii[8] = { kTabBorderRadius, kTabBorderRadius, |
| 79 kTabBorderRadius, kTabBorderRadius, | 108 kTabBorderRadius, kTabBorderRadius, |
| 80 0, 0, | 109 0, 0, |
| 81 0, 0 }; | 110 0, 0 }; |
| 82 path.addRoundRect(bounds, radii, SkPath::kCW_Direction); | 111 path.addRoundRect(bounds, radii, SkPath::kCW_Direction); |
| 83 | 112 |
| 84 SkPaint paint; | 113 SkPaint paint; |
| 85 paint.setAntiAlias(true); | 114 paint.setAntiAlias(true); |
| 86 paint.setStyle(SkPaint::kStroke_Style); | 115 paint.setStyle(SkPaint::kStroke_Style); |
| 87 paint.setColor(kTabBorderColor); | 116 paint.setColor(tab_colors_.border); |
| 88 paint.setStrokeWidth(kTabBorderThickness * 2); | 117 paint.setStrokeWidth(kTabBorderThickness * 2); |
| 89 | 118 |
| 90 canvas->DrawPath(path, paint); | 119 canvas->DrawPath(path, paint); |
| 91 } | 120 } |
| 92 | 121 |
| 93 void PaintTabTitle(gfx::Canvas* canvas, bool selected) { | 122 void PaintTabTitle(gfx::Canvas* canvas, bool selected) { |
| 94 int text_width = GetTabTitleFont().GetStringWidth(title_); | 123 int text_width = GetTabTitleFont(selected).GetStringWidth(title_); |
| 95 int text_height = GetTabTitleFont().GetHeight(); | 124 int text_height = GetTabTitleFont(selected).GetHeight(); |
| 96 int text_x = (width() - text_width) / 2; | 125 int text_x = (width() - text_width) / 2; |
| 97 int text_y = 5; | 126 int text_y = 5; |
| 98 gfx::Rect text_rect(text_x, text_y, text_width, text_height); | 127 gfx::Rect text_rect(text_x, text_y, text_width, text_height); |
| 99 canvas->DrawStringInt(title_, GetTabTitleFont(), title_color_, text_rect); | 128 canvas->DrawStringInt(title_, |
| 129 GetTabTitleFont(selected), |
| 130 title_color_, |
| 131 text_rect); |
| 100 } | 132 } |
| 101 | 133 |
| 102 void SetTitleColor(SkColor color) { | 134 void SetTitleColor(SkColor color) { |
| 103 title_color_ = color; | 135 title_color_ = color; |
| 104 SchedulePaint(); | 136 SchedulePaint(); |
| 105 } | 137 } |
| 106 | 138 |
| 107 const gfx::Font& GetTabTitleFont() { | 139 const gfx::Font& GetTabTitleFont(bool selected) { |
| 108 static gfx::Font* title_font = NULL; | 140 static gfx::Font* title_font_normal = NULL; |
| 109 if (!title_font) | 141 static gfx::Font* title_font_bold = NULL; |
| 110 title_font = new gfx::Font(gfx::Font().DeriveFont(0, gfx::Font::BOLD)); | 142 |
| 111 return *title_font; | 143 if (!title_font_normal) |
| 144 title_font_normal = new gfx::Font; |
| 145 if (!title_font_bold) |
| 146 title_font_bold = |
| 147 new gfx::Font(gfx::Font().DeriveFont(0, gfx::Font::BOLD)); |
| 148 |
| 149 if (!use_chrome_style_) |
| 150 return *title_font_bold; |
| 151 else |
| 152 return selected ? *title_font_bold : *title_font_normal; |
| 112 } | 153 } |
| 113 | 154 |
| 114 TabStrip* tab_strip_; | 155 TabStrip* tab_strip_; |
| 115 string16 title_; | 156 string16 title_; |
| 116 View* contents_; | 157 View* contents_; |
| 158 bool use_chrome_style_; |
| 159 const TabColors& tab_colors_; |
| 117 SkColor title_color_; | 160 SkColor title_color_; |
| 118 | 161 |
| 119 DISALLOW_COPY_AND_ASSIGN(Tab); | 162 DISALLOW_COPY_AND_ASSIGN(Tab); |
| 120 }; | 163 }; |
| 121 | 164 |
| 122 class TabStrip : public View { | 165 class TabStrip : public View { |
| 123 public: | 166 public: |
| 124 explicit TabStrip(NativeTabbedPaneViews* owner) | 167 TabStrip(NativeTabbedPaneViews* owner, bool use_chrome_style) |
| 125 : owner_(owner), | 168 : owner_(owner), |
| 126 selected_tab_(NULL) { | 169 selected_tab_(NULL), |
| 127 const int kCount = 4; | 170 use_chrome_style_(use_chrome_style) { |
| 128 // The gradient colors are derived from the tabbed panes used for the | 171 if (!use_chrome_style) { |
| 129 // WebUI. | 172 const int kCount = 4; |
| 130 SkColor colors[] = { | 173 // The gradient colors are derived from the tabbed panes used for the |
| 174 // WebUI. |
| 175 SkColor colors[] = { |
| 131 SkColorSetRGB(0xff, 0xff, 0xff), | 176 SkColorSetRGB(0xff, 0xff, 0xff), |
| 132 SkColorSetRGB(0xff, 0xff, 0xff), | 177 SkColorSetRGB(0xff, 0xff, 0xff), |
| 133 SkColorSetRGB(0xfa, 0xfa, 0xfa), | 178 SkColorSetRGB(0xfa, 0xfa, 0xfa), |
| 134 SkColorSetRGB(0xf2, 0xf2, 0xf2) | 179 SkColorSetRGB(0xf2, 0xf2, 0xf2) |
| 135 }; | 180 }; |
| 136 // The relative positions of the gradient colors are derived from the | 181 // The relative positions of the gradient colors are derived from the |
| 137 // tabbed panes used for the WebUI. | 182 // tabbed panes used for the WebUI. |
| 138 SkScalar pos[4] = {0.0f, 0.6f, 0.8f, 1.0f}; | 183 SkScalar pos[4] = {0.0f, 0.6f, 0.8f, 1.0f}; |
| 139 set_background(Background::CreateVerticalMultiColorGradientBackground( | 184 set_background(Background::CreateVerticalMultiColorGradientBackground( |
| 140 colors, pos, kCount)); | 185 colors, pos, kCount)); |
| 186 } |
| 141 } | 187 } |
| 142 virtual ~TabStrip() {} | 188 virtual ~TabStrip() {} |
| 143 | 189 |
| 144 void SelectTab(View* tab) { | 190 void SelectTab(View* tab) { |
| 145 if (tab == selected_tab_) | 191 if (tab == selected_tab_) |
| 146 return; | 192 return; |
| 147 if (selected_tab_) | 193 if (selected_tab_) |
| 148 static_cast<Tab*>(selected_tab_)->OnSelectedStateChanged(false); | 194 static_cast<Tab*>(selected_tab_)->OnSelectedStateChanged(false); |
| 149 selected_tab_ = tab; | 195 selected_tab_ = tab; |
| 150 static_cast<Tab*>(selected_tab_)->OnSelectedStateChanged(true); | 196 static_cast<Tab*>(selected_tab_)->OnSelectedStateChanged(true); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 165 View* contents = Tab::GetContents(child_at(index)); | 211 View* contents = Tab::GetContents(child_at(index)); |
| 166 delete child_at(index); | 212 delete child_at(index); |
| 167 return contents; | 213 return contents; |
| 168 } | 214 } |
| 169 | 215 |
| 170 // Overridden from View: | 216 // Overridden from View: |
| 171 virtual gfx::Size GetPreferredSize() OVERRIDE { | 217 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 172 return gfx::Size(50, Tab::GetMinimumTabHeight()); | 218 return gfx::Size(50, Tab::GetMinimumTabHeight()); |
| 173 } | 219 } |
| 174 virtual void Layout() OVERRIDE { | 220 virtual void Layout() OVERRIDE { |
| 175 const int kTabOffset = 18; | 221 const int kTabOffset = use_chrome_style_ ? 9 : 18; |
| 176 int x = kTabOffset; // Layout tabs with an offset to the tabstrip border. | 222 int x = kTabOffset; // Layout tabs with an offset to the tabstrip border. |
| 177 for (int i = 0; i < child_count(); ++i) { | 223 for (int i = 0; i < child_count(); ++i) { |
| 178 gfx::Size ps = child_at(i)->GetPreferredSize(); | 224 gfx::Size ps = child_at(i)->GetPreferredSize(); |
| 179 child_at(i)->SetBounds(x, 0, ps.width(), ps.height()); | 225 child_at(i)->SetBounds(x, 0, ps.width(), ps.height()); |
| 180 x = child_at(i)->bounds().right(); | 226 x = child_at(i)->bounds().right(); |
| 181 } | 227 } |
| 182 } | 228 } |
| 183 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 229 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 184 OnPaintBackground(canvas); | 230 OnPaintBackground(canvas); |
| 185 | 231 |
| 186 // Draw the TabStrip border. | 232 // Draw the TabStrip border. |
| 187 SkPaint paint; | 233 SkPaint paint; |
| 188 paint.setColor(kTabBorderColor); | 234 paint.setColor(use_chrome_style_ ? |
| 235 chrome_style_colors.border : standard_colors.border); |
| 189 paint.setStrokeWidth(kTabBorderThickness); | 236 paint.setStrokeWidth(kTabBorderThickness); |
| 190 SkScalar line_y = SkIntToScalar(height()) - kTabBorderThickness; | 237 SkScalar line_y = SkIntToScalar(height()) - kTabBorderThickness; |
| 191 SkScalar line_width = SkIntToScalar(width()); | 238 SkScalar line_width = SkIntToScalar(width()); |
| 192 canvas->sk_canvas()->drawLine(0, line_y, line_width, line_y, paint); | 239 canvas->sk_canvas()->drawLine(0, line_y, line_width, line_y, paint); |
| 193 } | 240 } |
| 194 | 241 |
| 195 private: | 242 private: |
| 196 NativeTabbedPaneViews* owner_; | 243 NativeTabbedPaneViews* owner_; |
| 197 View* selected_tab_; | 244 View* selected_tab_; |
| 245 bool use_chrome_style_; |
| 198 | 246 |
| 199 DISALLOW_COPY_AND_ASSIGN(TabStrip); | 247 DISALLOW_COPY_AND_ASSIGN(TabStrip); |
| 200 }; | 248 }; |
| 201 | 249 |
| 202 void Tab::OnSelectedStateChanged(bool selected) { | 250 void Tab::OnSelectedStateChanged(bool selected) { |
| 203 SetTitleColor(selected ? kTabTitleColor_Active : kTabTitleColor_Inactive); | 251 SetTitleColor(selected ? tab_colors_.title_active : |
| 252 tab_colors_.title_inactive); |
| 204 } | 253 } |
| 205 | 254 |
| 206 void Tab::OnPaint(gfx::Canvas* canvas) { | 255 void Tab::OnPaint(gfx::Canvas* canvas) { |
| 207 bool selected = tab_strip_->IsTabSelected(this); | 256 bool selected = tab_strip_->IsTabSelected(this); |
| 208 if (selected) { | 257 if (selected) { |
| 209 PaintTabBackground(canvas); | 258 PaintTabBackground(canvas); |
| 210 PaintTabBorder(canvas); | 259 PaintTabBorder(canvas); |
| 211 } | 260 } |
| 212 PaintTabTitle(canvas, selected); | 261 PaintTabTitle(canvas, selected); |
| 213 } | 262 } |
| 214 | 263 |
| 215 bool Tab::OnMousePressed(const ui::MouseEvent& event) { | 264 bool Tab::OnMousePressed(const ui::MouseEvent& event) { |
| 216 SetTitleColor(kTabTitleColor_Pressed); | 265 SetTitleColor(tab_colors_.title_pressed); |
| 217 return true; | 266 return true; |
| 218 } | 267 } |
| 219 | 268 |
| 220 void Tab::OnMouseReleased(const ui::MouseEvent& event) { | 269 void Tab::OnMouseReleased(const ui::MouseEvent& event) { |
| 221 SetTitleColor(kTabTitleColor_Hovered); | 270 SetTitleColor(tab_colors_.title_hovered); |
| 222 tab_strip_->SelectTab(this); | 271 tab_strip_->SelectTab(this); |
| 223 } | 272 } |
| 224 | 273 |
| 225 void Tab::OnMouseCaptureLost() { | 274 void Tab::OnMouseCaptureLost() { |
| 226 SetTitleColor(kTabTitleColor_Inactive); | 275 SetTitleColor(tab_colors_.title_inactive); |
| 227 } | 276 } |
| 228 | 277 |
| 229 void Tab::OnMouseEntered(const ui::MouseEvent& event) { | 278 void Tab::OnMouseEntered(const ui::MouseEvent& event) { |
| 230 SetTitleColor(tab_strip_->IsTabSelected(this) ? kTabTitleColor_Active : | 279 SetTitleColor(tab_strip_->IsTabSelected(this) ? tab_colors_.title_active : |
| 231 kTabTitleColor_Hovered); | 280 tab_colors_.title_hovered); |
| 232 } | 281 } |
| 233 | 282 |
| 234 void Tab::OnMouseExited(const ui::MouseEvent& event) { | 283 void Tab::OnMouseExited(const ui::MouseEvent& event) { |
| 235 SetTitleColor(tab_strip_->IsTabSelected(this) ? kTabTitleColor_Active : | 284 SetTitleColor(tab_strip_->IsTabSelected(this) ? tab_colors_.title_active : |
| 236 kTabTitleColor_Inactive); | 285 tab_colors_.title_inactive); |
| 237 } | 286 } |
| 238 | 287 |
| 239 // Custom layout manager that takes care of sizing and displaying the tab pages. | 288 // Custom layout manager that takes care of sizing and displaying the tab pages. |
| 240 class TabLayout : public LayoutManager { | 289 class TabLayout : public LayoutManager { |
| 241 public: | 290 public: |
| 242 TabLayout() {} | 291 TabLayout() {} |
| 243 | 292 |
| 244 // Switches to the tab page identified. | 293 // Switches to the tab page identified. |
| 245 void SwitchToPage(View* host, View* page) { | 294 void SwitchToPage(View* host, View* page) { |
| 246 for (int i = 0; i < host->child_count(); ++i) { | 295 for (int i = 0; i < host->child_count(); ++i) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 340 } |
| 292 return height; | 341 return height; |
| 293 } | 342 } |
| 294 | 343 |
| 295 DISALLOW_COPY_AND_ASSIGN(TabLayout); | 344 DISALLOW_COPY_AND_ASSIGN(TabLayout); |
| 296 }; | 345 }; |
| 297 | 346 |
| 298 //////////////////////////////////////////////////////////////////////////////// | 347 //////////////////////////////////////////////////////////////////////////////// |
| 299 // NativeTabbedPaneViews, public: | 348 // NativeTabbedPaneViews, public: |
| 300 | 349 |
| 301 NativeTabbedPaneViews::NativeTabbedPaneViews(TabbedPane* tabbed_pane) | 350 NativeTabbedPaneViews::NativeTabbedPaneViews(TabbedPane* tabbed_pane, |
| 351 bool use_chrome_style) |
| 302 : tabbed_pane_(tabbed_pane), | 352 : tabbed_pane_(tabbed_pane), |
| 303 tab_layout_manager_(new TabLayout), | 353 tab_layout_manager_(new TabLayout), |
| 304 ALLOW_THIS_IN_INITIALIZER_LIST(tab_strip_(new TabStrip(this))), | 354 ALLOW_THIS_IN_INITIALIZER_LIST(tab_strip_( |
| 305 content_view_(new views::View) { | 355 new TabStrip(this, use_chrome_style))), |
| 356 content_view_(new views::View), |
| 357 use_chrome_style_(use_chrome_style) { |
| 306 AddChildView(tab_strip_); | 358 AddChildView(tab_strip_); |
| 307 AddChildView(content_view_); | 359 AddChildView(content_view_); |
| 308 InitControl(); | 360 InitControl(); |
| 309 } | 361 } |
| 310 | 362 |
| 311 NativeTabbedPaneViews::~NativeTabbedPaneViews() { | 363 NativeTabbedPaneViews::~NativeTabbedPaneViews() { |
| 312 } | 364 } |
| 313 | 365 |
| 314 void NativeTabbedPaneViews::TabSelectionChanged(View* selected) { | 366 void NativeTabbedPaneViews::TabSelectionChanged(View* selected) { |
| 315 tab_layout_manager_->SwitchToPage(content_view_, Tab::GetContents(selected)); | 367 tab_layout_manager_->SwitchToPage(content_view_, Tab::GetContents(selected)); |
| 316 if (tabbed_pane_->listener()) | 368 if (tabbed_pane_->listener()) |
| 317 tabbed_pane_->listener()->TabSelectedAt(tab_strip_->GetIndexOf(selected)); | 369 tabbed_pane_->listener()->TabSelectedAt(tab_strip_->GetIndexOf(selected)); |
| 318 } | 370 } |
| 319 | 371 |
| 320 //////////////////////////////////////////////////////////////////////////////// | 372 //////////////////////////////////////////////////////////////////////////////// |
| 321 // NativeTabbedPaneViews, NativeTabbedPaneWrapper implementation: | 373 // NativeTabbedPaneViews, NativeTabbedPaneWrapper implementation: |
| 322 | 374 |
| 323 void NativeTabbedPaneViews::AddTab(const string16& title, View* contents) { | 375 void NativeTabbedPaneViews::AddTab(const string16& title, View* contents) { |
| 324 AddTabAtIndex(tab_strip_->child_count(), title, contents, true); | 376 AddTabAtIndex(tab_strip_->child_count(), title, contents, true); |
| 325 } | 377 } |
| 326 | 378 |
| 327 void NativeTabbedPaneViews::AddTabAtIndex(int index, | 379 void NativeTabbedPaneViews::AddTabAtIndex(int index, |
| 328 const string16& title, | 380 const string16& title, |
| 329 View* contents, | 381 View* contents, |
| 330 bool select_if_first_tab) { | 382 bool select_if_first_tab) { |
| 331 DCHECK(index <= static_cast<int>(tab_strip_->child_count())); | 383 DCHECK(index <= static_cast<int>(tab_strip_->child_count())); |
| 332 contents->set_owned_by_client(); | 384 contents->set_owned_by_client(); |
| 333 contents->SetVisible(false); | 385 contents->SetVisible(false); |
| 334 | 386 |
| 335 tab_strip_->AddChildViewAt(new Tab(tab_strip_, title, contents), index); | 387 tab_strip_->AddChildViewAt( |
| 388 new Tab(tab_strip_, title, contents, use_chrome_style_), |
| 389 index); |
| 336 | 390 |
| 337 // Add native tab only if the native control is already created. | 391 // Add native tab only if the native control is already created. |
| 338 content_view_->AddChildViewAt(contents, index); | 392 content_view_->AddChildViewAt(contents, index); |
| 339 | 393 |
| 340 // Switch to the newly added tab if requested; | 394 // Switch to the newly added tab if requested; |
| 341 if (tab_strip_->child_count() == 1 && select_if_first_tab) | 395 if (tab_strip_->child_count() == 1 && select_if_first_tab) |
| 342 tab_layout_manager_->SwitchToPage(content_view_, contents); | 396 tab_layout_manager_->SwitchToPage(content_view_, contents); |
| 343 if (!tab_strip_->selected_tab()) | 397 if (!tab_strip_->selected_tab()) |
| 344 tab_strip_->SelectTab(tab_strip_->child_at(0)); | 398 tab_strip_->SelectTab(tab_strip_->child_at(0)); |
| 345 } | 399 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 if (tab_strip_->has_children()) | 473 if (tab_strip_->has_children()) |
| 420 InitializeTabs(); | 474 InitializeTabs(); |
| 421 } | 475 } |
| 422 | 476 |
| 423 void NativeTabbedPaneViews::InitializeTabs() { | 477 void NativeTabbedPaneViews::InitializeTabs() { |
| 424 for (int i = 0; i < tab_strip_->child_count(); ++i) | 478 for (int i = 0; i < tab_strip_->child_count(); ++i) |
| 425 content_view_->AddChildView(Tab::GetContents(tab_strip_->child_at(i))); | 479 content_view_->AddChildView(Tab::GetContents(tab_strip_->child_at(i))); |
| 426 } | 480 } |
| 427 | 481 |
| 428 } // namespace views | 482 } // namespace views |
| OLD | NEW |