| 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/focus/focus_manager.h" | 5 #include "ui/views/focus/focus_manager.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "ui/base/models/combobox_model.h" | 10 #include "ui/base/models/combobox_model.h" |
| 11 #include "ui/views/controls/button/checkbox.h" | 11 #include "ui/views/controls/button/checkbox.h" |
| 12 #include "ui/views/controls/button/label_button.h" | |
| 13 #include "ui/views/controls/button/radio_button.h" | 12 #include "ui/views/controls/button/radio_button.h" |
| 13 #include "ui/views/controls/button/text_button.h" |
| 14 #include "ui/views/controls/combobox/combobox.h" | 14 #include "ui/views/controls/combobox/combobox.h" |
| 15 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/controls/link.h" | 16 #include "ui/views/controls/link.h" |
| 17 #include "ui/views/controls/native/native_view_host.h" | 17 #include "ui/views/controls/native/native_view_host.h" |
| 18 #include "ui/views/controls/scroll_view.h" | 18 #include "ui/views/controls/scroll_view.h" |
| 19 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" | 19 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
| 20 #include "ui/views/controls/textfield/textfield.h" | 20 #include "ui/views/controls/textfield/textfield.h" |
| 21 #include "ui/views/focus/accelerator_handler.h" | 21 #include "ui/views/focus/accelerator_handler.h" |
| 22 #include "ui/views/focus/focus_manager_test.h" | 22 #include "ui/views/focus/focus_manager_test.h" |
| 23 #include "ui/views/widget/root_view.h" | 23 #include "ui/views/widget/root_view.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 public: | 97 public: |
| 98 PaneView() : focus_search_(NULL) {} | 98 PaneView() : focus_search_(NULL) {} |
| 99 | 99 |
| 100 // If this method is called, this view will use GetPaneFocusTraversable to | 100 // If this method is called, this view will use GetPaneFocusTraversable to |
| 101 // have this provided FocusSearch used instead of the default one, allowing | 101 // have this provided FocusSearch used instead of the default one, allowing |
| 102 // you to trap focus within the pane. | 102 // you to trap focus within the pane. |
| 103 void EnablePaneFocus(FocusSearch* focus_search) { | 103 void EnablePaneFocus(FocusSearch* focus_search) { |
| 104 focus_search_ = focus_search; | 104 focus_search_ = focus_search; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Overridden from View: | 107 // Overridden from views::View: |
| 108 virtual FocusTraversable* GetPaneFocusTraversable() OVERRIDE { | 108 virtual FocusTraversable* GetPaneFocusTraversable() OVERRIDE { |
| 109 if (focus_search_) | 109 if (focus_search_) |
| 110 return this; | 110 return this; |
| 111 else | 111 else |
| 112 return NULL; | 112 return NULL; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Overridden from FocusTraversable: | 115 // Overridden from views::FocusTraversable: |
| 116 virtual FocusSearch* GetFocusSearch() OVERRIDE { | 116 virtual views::FocusSearch* GetFocusSearch() OVERRIDE { |
| 117 return focus_search_; | 117 return focus_search_; |
| 118 } | 118 } |
| 119 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE { | 119 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE { |
| 120 return NULL; | 120 return NULL; |
| 121 } | 121 } |
| 122 virtual View* GetFocusTraversableParentView() OVERRIDE { | 122 virtual View* GetFocusTraversableParentView() OVERRIDE { |
| 123 return NULL; | 123 return NULL; |
| 124 } | 124 } |
| 125 | 125 |
| 126 private: | 126 private: |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 label->SetBounds(label_x, y, label_width, label_height); | 352 label->SetBounds(label_x, y, label_width, label_height); |
| 353 | 353 |
| 354 text_field = new Textfield(); | 354 text_field = new Textfield(); |
| 355 text_field->set_id(kKiwiTextfieldID); | 355 text_field->set_id(kKiwiTextfieldID); |
| 356 left_container_->AddChildView(text_field); | 356 left_container_->AddChildView(text_field); |
| 357 text_field->SetBounds(label_x + label_width + 5, y, | 357 text_field->SetBounds(label_x + label_width + 5, y, |
| 358 text_field_width, label_height); | 358 text_field_width, label_height); |
| 359 | 359 |
| 360 y += label_height + gap_between_labels; | 360 y += label_height + gap_between_labels; |
| 361 | 361 |
| 362 LabelButton* button = new LabelButton(NULL, ASCIIToUTF16("Click me")); | 362 NativeTextButton* button = new NativeTextButton(NULL, |
| 363 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); | 363 ASCIIToUTF16("Click me")); |
| 364 button->SetBounds(label_x, y + 10, 80, 30); | 364 button->SetBounds(label_x, y + 10, 80, 30); |
| 365 button->set_id(kFruitButtonID); | 365 button->set_id(kFruitButtonID); |
| 366 left_container_->AddChildView(button); | 366 left_container_->AddChildView(button); |
| 367 y += 40; | 367 y += 40; |
| 368 | 368 |
| 369 cb = new Checkbox(ASCIIToUTF16("This is another check box")); | 369 cb = new Checkbox(ASCIIToUTF16("This is another check box")); |
| 370 cb->SetBounds(label_x + label_width + 5, y, 180, 20); | 370 cb->SetBounds(label_x + label_width + 5, y, 180, 20); |
| 371 cb->set_id(kFruitCheckBoxID); | 371 cb->set_id(kFruitCheckBoxID); |
| 372 left_container_->AddChildView(cb); | 372 left_container_->AddChildView(cb); |
| 373 y += 20; | 373 y += 20; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 Link* link = new Link(ASCIIToUTF16(kTitles[i])); | 448 Link* link = new Link(ASCIIToUTF16(kTitles[i])); |
| 449 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 449 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 450 link->set_id(kIDs[i]); | 450 link->set_id(kIDs[i]); |
| 451 scroll_content->AddChildView(link); | 451 scroll_content->AddChildView(link); |
| 452 link->SetBounds(5, y, 300, 15); | 452 link->SetBounds(5, y, 300, 15); |
| 453 y += 15; | 453 y += 15; |
| 454 } | 454 } |
| 455 | 455 |
| 456 y = 250; | 456 y = 250; |
| 457 int width = 60; | 457 int width = 60; |
| 458 button = new LabelButton(NULL, ASCIIToUTF16("OK")); | 458 button = new NativeTextButton(NULL, ASCIIToUTF16("OK")); |
| 459 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); | |
| 460 button->set_id(kOKButtonID); | 459 button->set_id(kOKButtonID); |
| 461 button->SetIsDefault(true); | 460 button->SetIsDefault(true); |
| 462 | 461 |
| 463 GetContentsView()->AddChildView(button); | 462 GetContentsView()->AddChildView(button); |
| 464 button->SetBounds(150, y, width, 30); | 463 button->SetBounds(150, y, width, 30); |
| 465 | 464 |
| 466 button = new LabelButton(NULL, ASCIIToUTF16("Cancel")); | 465 button = new NativeTextButton(NULL, ASCIIToUTF16("Cancel")); |
| 467 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); | |
| 468 button->set_id(kCancelButtonID); | 466 button->set_id(kCancelButtonID); |
| 469 GetContentsView()->AddChildView(button); | 467 GetContentsView()->AddChildView(button); |
| 470 button->SetBounds(220, y, width, 30); | 468 button->SetBounds(220, y, width, 30); |
| 471 | 469 |
| 472 button = new LabelButton(NULL, ASCIIToUTF16("Help")); | 470 button = new NativeTextButton(NULL, ASCIIToUTF16("Help")); |
| 473 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); | |
| 474 button->set_id(kHelpButtonID); | 471 button->set_id(kHelpButtonID); |
| 475 GetContentsView()->AddChildView(button); | 472 GetContentsView()->AddChildView(button); |
| 476 button->SetBounds(290, y, width, 30); | 473 button->SetBounds(290, y, width, 30); |
| 477 | 474 |
| 478 y += 40; | 475 y += 40; |
| 479 | 476 |
| 480 View* contents = NULL; | 477 View* contents = NULL; |
| 481 Link* link = NULL; | 478 Link* link = NULL; |
| 482 | 479 |
| 483 // Left bottom box with style checkboxes. | 480 // Left bottom box with style checkboxes. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 style_tab_->AddTab(ASCIIToUTF16("Other"), new View()); | 513 style_tab_->AddTab(ASCIIToUTF16("Other"), new View()); |
| 517 | 514 |
| 518 // Right bottom box with search. | 515 // Right bottom box with search. |
| 519 contents = new View(); | 516 contents = new View(); |
| 520 contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); | 517 contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); |
| 521 text_field = new Textfield(); | 518 text_field = new Textfield(); |
| 522 contents->AddChildView(text_field); | 519 contents->AddChildView(text_field); |
| 523 text_field->SetBounds(10, 10, 100, 20); | 520 text_field->SetBounds(10, 10, 100, 20); |
| 524 text_field->set_id(kSearchTextfieldID); | 521 text_field->set_id(kSearchTextfieldID); |
| 525 | 522 |
| 526 button = new LabelButton(NULL, ASCIIToUTF16("Search")); | 523 button = new NativeTextButton(NULL, ASCIIToUTF16("Search")); |
| 527 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); | |
| 528 contents->AddChildView(button); | 524 contents->AddChildView(button); |
| 529 button->SetBounds(112, 5, 60, 30); | 525 button->SetBounds(112, 5, 60, 30); |
| 530 button->set_id(kSearchButtonID); | 526 button->set_id(kSearchButtonID); |
| 531 | 527 |
| 532 link = new Link(ASCIIToUTF16("Help")); | 528 link = new Link(ASCIIToUTF16("Help")); |
| 533 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 529 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 534 link->set_id(kHelpLinkID); | 530 link->set_id(kHelpLinkID); |
| 535 contents->AddChildView(link); | 531 contents->AddChildView(link); |
| 536 link->SetBounds(175, 10, 30, 20); | 532 link->SetBounds(175, 10, 30, 20); |
| 537 | 533 |
| 538 search_border_view_ = new BorderView(contents); | 534 search_border_view_ = new BorderView(contents); |
| 539 search_border_view_->set_id(kSearchContainerID); | 535 search_border_view_->set_id(kSearchContainerID); |
| 540 | 536 |
| 541 GetContentsView()->AddChildView(search_border_view_); | 537 GetContentsView()->AddChildView(search_border_view_); |
| 542 search_border_view_->SetBounds(300, y, 240, 50); | 538 search_border_view_->SetBounds(300, y, 240, 50); |
| 543 | 539 |
| 544 y += 60; | 540 y += 60; |
| 545 | 541 |
| 546 contents = new View(); | 542 contents = new View(); |
| 547 contents->set_focusable(true); | 543 contents->set_focusable(true); |
| 548 contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE)); | 544 contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE)); |
| 549 contents->set_id(kThumbnailContainerID); | 545 contents->set_id(kThumbnailContainerID); |
| 550 button = new LabelButton(NULL, ASCIIToUTF16("Star")); | 546 button = new NativeTextButton(NULL, ASCIIToUTF16("Star")); |
| 551 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); | |
| 552 contents->AddChildView(button); | 547 contents->AddChildView(button); |
| 553 button->SetBounds(5, 5, 50, 30); | 548 button->SetBounds(5, 5, 50, 30); |
| 554 button->set_id(kThumbnailStarID); | 549 button->set_id(kThumbnailStarID); |
| 555 button = new LabelButton(NULL, ASCIIToUTF16("SuperStar")); | 550 button = new NativeTextButton(NULL, ASCIIToUTF16("SuperStar")); |
| 556 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); | |
| 557 contents->AddChildView(button); | 551 contents->AddChildView(button); |
| 558 button->SetBounds(60, 5, 100, 30); | 552 button->SetBounds(60, 5, 100, 30); |
| 559 button->set_id(kThumbnailSuperStarID); | 553 button->set_id(kThumbnailSuperStarID); |
| 560 | 554 |
| 561 GetContentsView()->AddChildView(contents); | 555 GetContentsView()->AddChildView(contents); |
| 562 contents->SetBounds(250, y, 200, 50); | 556 contents->SetBounds(250, y, 200, 50); |
| 563 // We can only call RadioButton::SetChecked() on the radio-button is part of | 557 // We can only call RadioButton::SetChecked() on the radio-button is part of |
| 564 // the view hierarchy. | 558 // the view hierarchy. |
| 565 radio_button_to_check->SetChecked(true); | 559 radio_button_to_check->SetChecked(true); |
| 566 } | 560 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 GetFocusManager()->AdvanceFocus(true); | 775 GetFocusManager()->AdvanceFocus(true); |
| 782 View* focused_view = GetFocusManager()->GetFocusedView(); | 776 View* focused_view = GetFocusManager()->GetFocusedView(); |
| 783 EXPECT_TRUE(focused_view != NULL); | 777 EXPECT_TRUE(focused_view != NULL); |
| 784 if (focused_view) | 778 if (focused_view) |
| 785 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); | 779 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); |
| 786 } | 780 } |
| 787 } | 781 } |
| 788 } | 782 } |
| 789 | 783 |
| 790 } // namespace views | 784 } // namespace views |
| OLD | NEW |