| 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/tabbed_pane.h" | 5 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "third_party/skia/include/core/SkPaint.h" | 9 #include "third_party/skia/include/core/SkPaint.h" |
| 10 #include "third_party/skia/include/core/SkPath.h" | 10 #include "third_party/skia/include/core/SkPath.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 void SetSelected(bool selected); | 61 void SetSelected(bool selected); |
| 62 | 62 |
| 63 // Overridden from View: | 63 // Overridden from View: |
| 64 bool OnMousePressed(const ui::MouseEvent& event) override; | 64 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 65 void OnMouseEntered(const ui::MouseEvent& event) override; | 65 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 66 void OnMouseExited(const ui::MouseEvent& event) override; | 66 void OnMouseExited(const ui::MouseEvent& event) override; |
| 67 void OnGestureEvent(ui::GestureEvent* event) override; | 67 void OnGestureEvent(ui::GestureEvent* event) override; |
| 68 gfx::Size GetPreferredSize() const override; | 68 gfx::Size GetPreferredSize() const override; |
| 69 void Layout() override; | 69 void Layout() override; |
| 70 const char* GetClassName() const override; | 70 const char* GetClassName() const override; |
| 71 void OnFocus() override; |
| 72 void OnBlur() override; |
| 73 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 71 | 74 |
| 72 protected: | 75 protected: |
| 73 Label* title() { return title_; } | 76 Label* title() { return title_; } |
| 74 | 77 |
| 75 // Called whenever |tab_state_| changes. | 78 // Called whenever |tab_state_| changes. |
| 76 virtual void OnStateChanged(); | 79 virtual void OnStateChanged(); |
| 77 | 80 |
| 81 // Returns whether the containing TabStrip has focus. |
| 82 bool ContainerHasFocus(); |
| 83 |
| 78 private: | 84 private: |
| 79 enum TabState { | 85 enum TabState { |
| 80 TAB_INACTIVE, | 86 TAB_INACTIVE, |
| 81 TAB_ACTIVE, | 87 TAB_ACTIVE, |
| 82 TAB_HOVERED, | 88 TAB_HOVERED, |
| 83 }; | 89 }; |
| 84 | 90 |
| 85 void SetState(TabState tab_state); | 91 void SetState(TabState tab_state); |
| 86 | 92 |
| 87 TabbedPane* tabbed_pane_; | 93 TabbedPane* tabbed_pane_; |
| 88 Label* title_; | 94 Label* title_; |
| 89 gfx::Size preferred_title_size_; | 95 gfx::Size preferred_title_size_; |
| 90 TabState tab_state_; | 96 TabState tab_state_; |
| 91 // The content view associated with this tab. | 97 // The content view associated with this tab. |
| 92 View* contents_; | 98 View* contents_; |
| 93 | 99 |
| 94 DISALLOW_COPY_AND_ASSIGN(Tab); | 100 DISALLOW_COPY_AND_ASSIGN(Tab); |
| 95 }; | 101 }; |
| 96 | 102 |
| 97 // A subclass of Tab that implements the Harmony visual styling. | 103 // A subclass of Tab that implements the Harmony visual styling. |
| 98 class MdTab : public Tab { | 104 class MdTab : public Tab { |
| 99 public: | 105 public: |
| 100 MdTab(TabbedPane* tabbed_pane, const base::string16& title, View* contents); | 106 MdTab(TabbedPane* tabbed_pane, const base::string16& title, View* contents); |
| 101 ~MdTab() override; | 107 ~MdTab() override; |
| 102 | 108 |
| 103 // Overridden from Tab: | 109 // Overridden from Tab: |
| 104 void OnStateChanged() override; | 110 void OnStateChanged() override; |
| 105 | 111 |
| 112 // Overridden from View: |
| 113 void OnPaintBorder(gfx::Canvas* canvas) override; |
| 114 |
| 106 private: | 115 private: |
| 107 DISALLOW_COPY_AND_ASSIGN(MdTab); | 116 DISALLOW_COPY_AND_ASSIGN(MdTab); |
| 108 }; | 117 }; |
| 109 | 118 |
| 110 // The tab strip shown above the tab contents. | 119 // The tab strip shown above the tab contents. |
| 111 class TabStrip : public View { | 120 class TabStrip : public View { |
| 112 public: | 121 public: |
| 113 // Internal class name. | 122 // Internal class name. |
| 114 static const char kViewClassName[]; | 123 static const char kViewClassName[]; |
| 115 | 124 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 171 |
| 163 SetState(TAB_INACTIVE); | 172 SetState(TAB_INACTIVE); |
| 164 AddChildView(title_); | 173 AddChildView(title_); |
| 165 } | 174 } |
| 166 | 175 |
| 167 Tab::~Tab() {} | 176 Tab::~Tab() {} |
| 168 | 177 |
| 169 void Tab::SetSelected(bool selected) { | 178 void Tab::SetSelected(bool selected) { |
| 170 contents_->SetVisible(selected); | 179 contents_->SetVisible(selected); |
| 171 SetState(selected ? TAB_ACTIVE : TAB_INACTIVE); | 180 SetState(selected ? TAB_ACTIVE : TAB_INACTIVE); |
| 181 #if defined(OS_MACOSX) |
| 182 SetFocusBehavior(selected ? FocusBehavior::ACCESSIBLE_ONLY |
| 183 : FocusBehavior::NEVER); |
| 184 #else |
| 185 SetFocusBehavior(selected ? FocusBehavior::ALWAYS : FocusBehavior::NEVER); |
| 186 #endif |
| 172 } | 187 } |
| 173 | 188 |
| 174 void Tab::OnStateChanged() { | 189 void Tab::OnStateChanged() { |
| 175 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 190 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 176 switch (tab_state_) { | 191 switch (tab_state_) { |
| 177 case TAB_INACTIVE: | 192 case TAB_INACTIVE: |
| 178 title_->SetEnabledColor(kTabTitleColor_Inactive); | 193 title_->SetEnabledColor(kTabTitleColor_Inactive); |
| 179 title_->SetFontList(rb.GetFontListWithDelta( | 194 title_->SetFontList(rb.GetFontListWithDelta( |
| 180 ui::kLabelFontSizeDelta, gfx::Font::NORMAL, kInactiveWeight)); | 195 ui::kLabelFontSizeDelta, gfx::Font::NORMAL, kInactiveWeight)); |
| 181 break; | 196 break; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 260 } |
| 246 | 261 |
| 247 void Tab::SetState(TabState tab_state) { | 262 void Tab::SetState(TabState tab_state) { |
| 248 if (tab_state == tab_state_) | 263 if (tab_state == tab_state_) |
| 249 return; | 264 return; |
| 250 tab_state_ = tab_state; | 265 tab_state_ = tab_state; |
| 251 OnStateChanged(); | 266 OnStateChanged(); |
| 252 SchedulePaint(); | 267 SchedulePaint(); |
| 253 } | 268 } |
| 254 | 269 |
| 270 bool Tab::ContainerHasFocus() { |
| 271 return tabbed_pane_->HasFocus(); |
| 272 } |
| 273 |
| 274 void Tab::OnFocus() { |
| 275 OnStateChanged(); |
| 276 // When the tab gains focus, send an accessibility event indicating that the |
| 277 // contents are focused. When the tab loses focus, whichever new View ends up |
| 278 // with focus will send an AX_EVENT_FOCUS of its own, so there's no need to |
| 279 // send one in OnBlur(). |
| 280 if (contents()) |
| 281 contents()->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
| 282 SchedulePaint(); |
| 283 } |
| 284 |
| 285 void Tab::OnBlur() { |
| 286 OnStateChanged(); |
| 287 SchedulePaint(); |
| 288 } |
| 289 |
| 290 bool Tab::OnKeyPressed(const ui::KeyEvent& event) { |
| 291 ui::KeyboardCode key = event.key_code(); |
| 292 if (key != ui::VKEY_LEFT && key != ui::VKEY_RIGHT) |
| 293 return false; |
| 294 return tabbed_pane_->MoveSelectionBy(key == ui::VKEY_RIGHT ? 1 : -1); |
| 295 } |
| 296 |
| 255 MdTab::MdTab(TabbedPane* tabbed_pane, | 297 MdTab::MdTab(TabbedPane* tabbed_pane, |
| 256 const base::string16& title, | 298 const base::string16& title, |
| 257 View* contents) | 299 View* contents) |
| 258 : Tab(tabbed_pane, title, contents) { | 300 : Tab(tabbed_pane, title, contents) { |
| 259 OnStateChanged(); | 301 OnStateChanged(); |
| 260 } | 302 } |
| 261 | 303 |
| 262 MdTab::~MdTab() {} | 304 MdTab::~MdTab() {} |
| 263 | 305 |
| 264 void MdTab::OnStateChanged() { | 306 void MdTab::OnStateChanged() { |
| 265 ui::NativeTheme* theme = GetNativeTheme(); | 307 ui::NativeTheme* theme = GetNativeTheme(); |
| 266 SkColor border_color = theme->GetSystemColor( | |
| 267 selected() ? ui::NativeTheme::kColorId_FocusedBorderColor | |
| 268 : ui::NativeTheme::kColorId_UnfocusedBorderColor); | |
| 269 int border_thickness = selected() ? 2 : 1; | |
| 270 SetBorder( | |
| 271 Border::CreateSolidSidedBorder(0, 0, border_thickness, 0, border_color)); | |
| 272 | 308 |
| 273 SkColor font_color = selected() | 309 SkColor font_color = selected() |
| 274 ? theme->GetSystemColor(ui::NativeTheme::kColorId_ProminentButtonColor) | 310 ? theme->GetSystemColor(ui::NativeTheme::kColorId_ProminentButtonColor) |
| 275 : theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor); | 311 : theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonEnabledColor); |
| 276 title()->SetEnabledColor(font_color); | 312 title()->SetEnabledColor(font_color); |
| 277 | 313 |
| 278 gfx::Font::Weight font_weight = gfx::Font::Weight::MEDIUM; | 314 gfx::Font::Weight font_weight = gfx::Font::Weight::MEDIUM; |
| 279 #if defined(OS_WIN) | 315 #if defined(OS_WIN) |
| 280 if (selected()) | 316 if (selected()) |
| 281 font_weight = gfx::Font::Weight::BOLD; | 317 font_weight = gfx::Font::Weight::BOLD; |
| 282 #endif | 318 #endif |
| 283 | 319 |
| 284 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 320 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 285 title()->SetFontList(rb.GetFontListWithDelta(ui::kLabelFontSizeDelta, | 321 title()->SetFontList(rb.GetFontListWithDelta(ui::kLabelFontSizeDelta, |
| 286 gfx::Font::NORMAL, font_weight)); | 322 gfx::Font::NORMAL, font_weight)); |
| 287 } | 323 } |
| 288 | 324 |
| 325 void MdTab::OnPaintBorder(gfx::Canvas* canvas) { |
| 326 const int kBorderStrokeWidth = 2; |
| 327 if (!HasFocus()) { |
| 328 SkColor color = GetNativeTheme()->GetSystemColor( |
| 329 selected() ? ui::NativeTheme::kColorId_FocusedBorderColor |
| 330 : ui::NativeTheme::kColorId_UnfocusedBorderColor); |
| 331 int thickness = selected() ? kBorderStrokeWidth : kBorderStrokeWidth / 2; |
| 332 canvas->FillRect(gfx::Rect(0, height() - thickness, width(), thickness), |
| 333 color); |
| 334 return; |
| 335 } |
| 336 |
| 337 // TODO(ellyjones): should this 0x66 be part of NativeTheme somehow? |
| 338 SkColor base_color = GetNativeTheme()->GetSystemColor( |
| 339 ui::NativeTheme::kColorId_FocusedBorderColor); |
| 340 SkColor light_color = SkColorSetA(base_color, 0x66); |
| 341 |
| 342 SkPaint paint; |
| 343 paint.setColor(light_color); |
| 344 paint.setStyle(SkPaint::kStroke_Style); |
| 345 paint.setStrokeWidth(kBorderStrokeWidth); |
| 346 |
| 347 gfx::RectF bounds = gfx::RectF(GetLocalBounds()); |
| 348 bounds.Inset(gfx::Insets(kBorderStrokeWidth / 2.f)); |
| 349 |
| 350 // Draw the lighter-colored stroke first, then draw the heavier stroke over |
| 351 // the bottom of it. This is fine because the heavier stroke has 1.0 alpha, so |
| 352 // the lighter stroke won't show through. |
| 353 canvas->DrawRect(bounds, paint); |
| 354 canvas->FillRect( |
| 355 gfx::Rect(0, height() - kBorderStrokeWidth, width(), kBorderStrokeWidth), |
| 356 base_color); |
| 357 } |
| 358 |
| 289 // static | 359 // static |
| 290 const char TabStrip::kViewClassName[] = "TabStrip"; | 360 const char TabStrip::kViewClassName[] = "TabStrip"; |
| 291 | 361 |
| 292 TabStrip::TabStrip(TabbedPane* tabbed_pane) : tabbed_pane_(tabbed_pane) {} | 362 TabStrip::TabStrip(TabbedPane* tabbed_pane) : tabbed_pane_(tabbed_pane) {} |
| 293 | 363 |
| 294 TabStrip::~TabStrip() {} | 364 TabStrip::~TabStrip() {} |
| 295 | 365 |
| 296 gfx::Size TabStrip::GetPreferredSize() const { | 366 gfx::Size TabStrip::GetPreferredSize() const { |
| 297 gfx::Size size; | 367 gfx::Size size; |
| 298 for (int i = 0; i < child_count(); ++i) { | 368 for (int i = 0; i < child_count(); ++i) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 OnPaintBackground(canvas); | 449 OnPaintBackground(canvas); |
| 380 } | 450 } |
| 381 | 451 |
| 382 TabbedPane::TabbedPane() | 452 TabbedPane::TabbedPane() |
| 383 : listener_(NULL), | 453 : listener_(NULL), |
| 384 tab_strip_(ui::MaterialDesignController::IsSecondaryUiMaterial() | 454 tab_strip_(ui::MaterialDesignController::IsSecondaryUiMaterial() |
| 385 ? new MdTabStrip(this) | 455 ? new MdTabStrip(this) |
| 386 : new TabStrip(this)), | 456 : new TabStrip(this)), |
| 387 contents_(new View()), | 457 contents_(new View()), |
| 388 selected_tab_index_(-1) { | 458 selected_tab_index_(-1) { |
| 389 #if defined(OS_MACOSX) | |
| 390 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | |
| 391 #else | |
| 392 SetFocusBehavior(FocusBehavior::ALWAYS); | |
| 393 #endif | |
| 394 | |
| 395 AddChildView(tab_strip_); | 459 AddChildView(tab_strip_); |
| 396 AddChildView(contents_); | 460 AddChildView(contents_); |
| 397 } | 461 } |
| 398 | 462 |
| 399 TabbedPane::~TabbedPane() {} | 463 TabbedPane::~TabbedPane() {} |
| 400 | 464 |
| 401 int TabbedPane::GetTabCount() { | 465 int TabbedPane::GetTabCount() { |
| 402 DCHECK_EQ(tab_strip_->child_count(), contents_->child_count()); | 466 DCHECK_EQ(tab_strip_->child_count(), contents_->child_count()); |
| 403 return contents_->child_count(); | 467 return contents_->child_count(); |
| 404 } | 468 } |
| 405 | 469 |
| 406 View* TabbedPane::GetSelectedTab() { | |
| 407 return selected_tab_index() < 0 ? | |
| 408 NULL : GetTabAt(selected_tab_index())->contents(); | |
| 409 } | |
| 410 | |
| 411 void TabbedPane::AddTab(const base::string16& title, View* contents) { | 470 void TabbedPane::AddTab(const base::string16& title, View* contents) { |
| 412 AddTabAtIndex(tab_strip_->child_count(), title, contents); | 471 AddTabAtIndex(tab_strip_->child_count(), title, contents); |
| 413 } | 472 } |
| 414 | 473 |
| 415 void TabbedPane::AddTabAtIndex(int index, | 474 void TabbedPane::AddTabAtIndex(int index, |
| 416 const base::string16& title, | 475 const base::string16& title, |
| 417 View* contents) { | 476 View* contents) { |
| 418 DCHECK(index >= 0 && index <= GetTabCount()); | 477 DCHECK(index >= 0 && index <= GetTabCount()); |
| 419 contents->SetVisible(false); | 478 contents->SetVisible(false); |
| 420 | 479 |
| 421 tab_strip_->AddChildViewAt( | 480 tab_strip_->AddChildViewAt( |
| 422 ui::MaterialDesignController::IsSecondaryUiMaterial() | 481 ui::MaterialDesignController::IsSecondaryUiMaterial() |
| 423 ? new MdTab(this, title, contents) | 482 ? new MdTab(this, title, contents) |
| 424 : new Tab(this, title, contents), | 483 : new Tab(this, title, contents), |
| 425 index); | 484 index); |
| 426 contents_->AddChildViewAt(contents, index); | 485 contents_->AddChildViewAt(contents, index); |
| 486 // TODO(ellyjones): if index < selected_tab_index(), selected_tab_index() gets |
| 487 // out of sync with which tab believes it is selected. This class should |
| 488 // directly ask Tabs whether they are selected. |
| 427 if (selected_tab_index() < 0) | 489 if (selected_tab_index() < 0) |
| 428 SelectTabAt(index); | 490 SelectTabAt(index); |
| 429 | 491 |
| 430 PreferredSizeChanged(); | 492 PreferredSizeChanged(); |
| 431 } | 493 } |
| 432 | 494 |
| 433 void TabbedPane::SelectTabAt(int index) { | 495 void TabbedPane::SelectTabAt(int index) { |
| 434 DCHECK(index >= 0 && index < GetTabCount()); | 496 DCHECK(index >= 0 && index < GetTabCount()); |
| 435 if (index == selected_tab_index()) | 497 if (index == selected_tab_index()) |
| 436 return; | 498 return; |
| 437 | 499 |
| 438 if (selected_tab_index() >= 0) | 500 Tab* old_selected_tab = GetSelectedTab(); |
| 439 GetTabAt(selected_tab_index())->SetSelected(false); | 501 Tab* new_selected_tab = GetTabAt(index); |
| 440 | 502 new_selected_tab->SetSelected(true); |
| 441 selected_tab_index_ = index; | 503 selected_tab_index_ = index; |
| 442 Tab* tab = GetTabAt(index); | 504 if (old_selected_tab) { |
| 443 tab->SetSelected(true); | 505 if (old_selected_tab->HasFocus()) |
| 506 new_selected_tab->RequestFocus(); |
| 507 old_selected_tab->SetSelected(false); |
| 508 } |
| 444 tab_strip_->SchedulePaint(); | 509 tab_strip_->SchedulePaint(); |
| 445 | 510 |
| 446 FocusManager* focus_manager = tab->contents()->GetFocusManager(); | 511 FocusManager* focus_manager = new_selected_tab->contents()->GetFocusManager(); |
| 447 if (focus_manager) { | 512 if (focus_manager) { |
| 448 const View* focused_view = focus_manager->GetFocusedView(); | 513 const View* focused_view = focus_manager->GetFocusedView(); |
| 449 if (focused_view && contents_->Contains(focused_view) && | 514 if (focused_view && contents_->Contains(focused_view) && |
| 450 !tab->contents()->Contains(focused_view)) | 515 !new_selected_tab->contents()->Contains(focused_view)) |
| 451 focus_manager->SetFocusedView(tab->contents()); | 516 focus_manager->SetFocusedView(new_selected_tab->contents()); |
| 452 } | 517 } |
| 453 | 518 |
| 454 if (listener()) | 519 if (listener()) |
| 455 listener()->TabSelectedAt(index); | 520 listener()->TabSelectedAt(index); |
| 456 } | 521 } |
| 457 | 522 |
| 458 void TabbedPane::SelectTab(Tab* tab) { | 523 void TabbedPane::SelectTab(Tab* tab) { |
| 459 const int index = tab_strip_->GetIndexOf(tab); | 524 const int index = tab_strip_->GetIndexOf(tab); |
| 460 if (index >= 0) | 525 if (index >= 0) |
| 461 SelectTabAt(index); | 526 SelectTabAt(index); |
| 462 } | 527 } |
| 463 | 528 |
| 464 gfx::Size TabbedPane::GetPreferredSize() const { | 529 gfx::Size TabbedPane::GetPreferredSize() const { |
| 465 gfx::Size size; | 530 gfx::Size size; |
| 466 for (int i = 0; i < contents_->child_count(); ++i) | 531 for (int i = 0; i < contents_->child_count(); ++i) |
| 467 size.SetToMax(contents_->child_at(i)->GetPreferredSize()); | 532 size.SetToMax(contents_->child_at(i)->GetPreferredSize()); |
| 468 size.Enlarge(0, tab_strip_->GetPreferredSize().height()); | 533 size.Enlarge(0, tab_strip_->GetPreferredSize().height()); |
| 469 return size; | 534 return size; |
| 470 } | 535 } |
| 471 | 536 |
| 472 Tab* TabbedPane::GetTabAt(int index) { | 537 Tab* TabbedPane::GetTabAt(int index) { |
| 473 return static_cast<Tab*>(tab_strip_->child_at(index)); | 538 return static_cast<Tab*>(tab_strip_->child_at(index)); |
| 474 } | 539 } |
| 475 | 540 |
| 541 Tab* TabbedPane::GetSelectedTab() { |
| 542 return selected_tab_index() >= 0 ? GetTabAt(selected_tab_index()) : nullptr; |
| 543 } |
| 544 |
| 545 bool TabbedPane::MoveSelectionBy(int delta) { |
| 546 const int tab_count = GetTabCount(); |
| 547 if (tab_count <= 1) |
| 548 return false; |
| 549 int next_selected_index = (selected_tab_index() + delta) % tab_count; |
| 550 if (next_selected_index < 0) |
| 551 next_selected_index += tab_count; |
| 552 SelectTabAt(next_selected_index); |
| 553 return true; |
| 554 } |
| 555 |
| 476 void TabbedPane::Layout() { | 556 void TabbedPane::Layout() { |
| 477 const gfx::Size size = tab_strip_->GetPreferredSize(); | 557 const gfx::Size size = tab_strip_->GetPreferredSize(); |
| 478 tab_strip_->SetBounds(0, 0, width(), size.height()); | 558 tab_strip_->SetBounds(0, 0, width(), size.height()); |
| 479 contents_->SetBounds(0, tab_strip_->bounds().bottom(), width(), | 559 contents_->SetBounds(0, tab_strip_->bounds().bottom(), width(), |
| 480 std::max(0, height() - size.height())); | 560 std::max(0, height() - size.height())); |
| 481 for (int i = 0; i < contents_->child_count(); ++i) | 561 for (int i = 0; i < contents_->child_count(); ++i) |
| 482 contents_->child_at(i)->SetSize(contents_->size()); | 562 contents_->child_at(i)->SetSize(contents_->size()); |
| 483 } | 563 } |
| 484 | 564 |
| 485 void TabbedPane::ViewHierarchyChanged( | 565 void TabbedPane::ViewHierarchyChanged( |
| 486 const ViewHierarchyChangedDetails& details) { | 566 const ViewHierarchyChangedDetails& details) { |
| 487 if (details.is_add) { | 567 if (details.is_add) { |
| 488 // Support navigating tabs by Ctrl+Tab and Ctrl+Shift+Tab. | 568 // Support navigating tabs by Ctrl+Tab and Ctrl+Shift+Tab. |
| 489 AddAccelerator(ui::Accelerator(ui::VKEY_TAB, | 569 AddAccelerator(ui::Accelerator(ui::VKEY_TAB, |
| 490 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN)); | 570 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN)); |
| 491 AddAccelerator(ui::Accelerator(ui::VKEY_TAB, ui::EF_CONTROL_DOWN)); | 571 AddAccelerator(ui::Accelerator(ui::VKEY_TAB, ui::EF_CONTROL_DOWN)); |
| 492 } | 572 } |
| 493 } | 573 } |
| 494 | 574 |
| 495 bool TabbedPane::AcceleratorPressed(const ui::Accelerator& accelerator) { | 575 bool TabbedPane::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 496 // Handle Ctrl+Tab and Ctrl+Shift+Tab navigation of pages. | 576 // Handle Ctrl+Tab and Ctrl+Shift+Tab navigation of pages. |
| 497 DCHECK(accelerator.key_code() == ui::VKEY_TAB && accelerator.IsCtrlDown()); | 577 DCHECK(accelerator.key_code() == ui::VKEY_TAB && accelerator.IsCtrlDown()); |
| 498 const int tab_count = GetTabCount(); | 578 return MoveSelectionBy(accelerator.IsShiftDown() ? -1 : 1); |
| 499 if (tab_count <= 1) | |
| 500 return false; | |
| 501 const int increment = accelerator.IsShiftDown() ? -1 : 1; | |
| 502 int next_tab_index = (selected_tab_index() + increment) % tab_count; | |
| 503 // Wrap around. | |
| 504 if (next_tab_index < 0) | |
| 505 next_tab_index += tab_count; | |
| 506 SelectTabAt(next_tab_index); | |
| 507 return true; | |
| 508 } | 579 } |
| 509 | 580 |
| 510 const char* TabbedPane::GetClassName() const { | 581 const char* TabbedPane::GetClassName() const { |
| 511 return kViewClassName; | 582 return kViewClassName; |
| 512 } | 583 } |
| 513 | 584 |
| 514 void TabbedPane::OnFocus() { | 585 View* TabbedPane::GetSelectedTabContentView() { |
| 515 View::OnFocus(); | 586 return GetSelectedTab() ? GetSelectedTab()->contents() : nullptr; |
| 587 } |
| 516 | 588 |
| 517 View* selected_tab = GetSelectedTab(); | 589 View* TabbedPane::GetSelectedTabAsView() { |
| 518 if (selected_tab) { | 590 return GetSelectedTab(); |
| 519 selected_tab->NotifyAccessibilityEvent( | |
| 520 ui::AX_EVENT_FOCUS, true); | |
| 521 } | |
| 522 } | 591 } |
| 523 | 592 |
| 524 void TabbedPane::GetAccessibleState(ui::AXViewState* state) { | 593 void TabbedPane::GetAccessibleState(ui::AXViewState* state) { |
| 525 state->role = ui::AX_ROLE_TAB_LIST; | 594 state->role = ui::AX_ROLE_TAB_LIST; |
| 526 } | 595 } |
| 527 | 596 |
| 528 } // namespace views | 597 } // namespace views |
| OLD | NEW |