| 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/tree/tree_view.h" | 5 #include "ui/views/controls/tree/tree_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #include "ui/base/ime/input_method.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 14 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
| 15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/gfx/geometry/rect_conversions.h" | 18 #include "ui/gfx/geometry/rect_conversions.h" |
| 18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 19 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 20 #include "ui/native_theme/native_theme.h" | 21 #include "ui/native_theme/native_theme.h" |
| 21 #include "ui/resources/grit/ui_resources.h" | 22 #include "ui/resources/grit/ui_resources.h" |
| 22 #include "ui/views/controls/prefix_selector.h" | 23 #include "ui/views/controls/prefix_selector.h" |
| 23 #include "ui/views/controls/scroll_view.h" | 24 #include "ui/views/controls/scroll_view.h" |
| 24 #include "ui/views/controls/textfield/textfield.h" | 25 #include "ui/views/controls/textfield/textfield.h" |
| 25 #include "ui/views/controls/tree/tree_view_controller.h" | 26 #include "ui/views/controls/tree/tree_view_controller.h" |
| 26 #include "ui/views/ime/input_method.h" | |
| 27 #include "ui/views/resources/grit/views_resources.h" | 27 #include "ui/views/resources/grit/views_resources.h" |
| 28 | 28 |
| 29 using ui::TreeModel; | 29 using ui::TreeModel; |
| 30 using ui::TreeModelNode; | 30 using ui::TreeModelNode; |
| 31 | 31 |
| 32 namespace views { | 32 namespace views { |
| 33 | 33 |
| 34 // Insets around the view. | 34 // Insets around the view. |
| 35 static const int kHorizontalInset = 2; | 35 static const int kHorizontalInset = 2; |
| 36 static const int kVerticalInset = 2; | 36 static const int kVerticalInset = 2; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 open_icon_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 88 open_icon_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 89 (base::i18n::IsRTL() ? IDR_FOLDER_OPEN_RTL | 89 (base::i18n::IsRTL() ? IDR_FOLDER_OPEN_RTL |
| 90 : IDR_FOLDER_OPEN)).ToImageSkia(); | 90 : IDR_FOLDER_OPEN)).ToImageSkia(); |
| 91 text_offset_ = closed_icon_.width() + kImagePadding + kImagePadding + | 91 text_offset_ = closed_icon_.width() + kImagePadding + kImagePadding + |
| 92 kArrowRegionSize; | 92 kArrowRegionSize; |
| 93 } | 93 } |
| 94 | 94 |
| 95 TreeView::~TreeView() { | 95 TreeView::~TreeView() { |
| 96 if (model_) | 96 if (model_) |
| 97 model_->RemoveObserver(this); | 97 model_->RemoveObserver(this); |
| 98 |
| 99 if (GetInputMethod() && selector_.get()) { |
| 100 // TreeView should have been blurred before destroy. |
| 101 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); |
| 102 } |
| 103 |
| 98 if (focus_manager_) { | 104 if (focus_manager_) { |
| 99 focus_manager_->RemoveFocusChangeListener(this); | 105 focus_manager_->RemoveFocusChangeListener(this); |
| 100 focus_manager_ = NULL; | 106 focus_manager_ = NULL; |
| 101 } | 107 } |
| 102 } | 108 } |
| 103 | 109 |
| 104 View* TreeView::CreateParentIfNecessary() { | 110 View* TreeView::CreateParentIfNecessary() { |
| 105 ScrollView* scroll_view = ScrollView::CreateScrollViewWithBorder(); | 111 ScrollView* scroll_view = ScrollView::CreateScrollViewWithBorder(); |
| 106 scroll_view->SetContents(this); | 112 scroll_view->SetContents(this); |
| 107 return scroll_view; | 113 return scroll_view; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 CancelEdit(); | 369 CancelEdit(); |
| 364 RequestFocus(); | 370 RequestFocus(); |
| 365 } | 371 } |
| 366 return true; | 372 return true; |
| 367 } | 373 } |
| 368 | 374 |
| 369 bool TreeView::OnMousePressed(const ui::MouseEvent& event) { | 375 bool TreeView::OnMousePressed(const ui::MouseEvent& event) { |
| 370 return OnClickOrTap(event); | 376 return OnClickOrTap(event); |
| 371 } | 377 } |
| 372 | 378 |
| 373 ui::TextInputClient* TreeView::GetTextInputClient() { | |
| 374 if (!selector_) | |
| 375 selector_.reset(new PrefixSelector(this)); | |
| 376 return selector_.get(); | |
| 377 } | |
| 378 | |
| 379 void TreeView::OnGestureEvent(ui::GestureEvent* event) { | 379 void TreeView::OnGestureEvent(ui::GestureEvent* event) { |
| 380 if (event->type() == ui::ET_GESTURE_TAP) { | 380 if (event->type() == ui::ET_GESTURE_TAP) { |
| 381 if (OnClickOrTap(*event)) | 381 if (OnClickOrTap(*event)) |
| 382 event->SetHandled(); | 382 event->SetHandled(); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 void TreeView::ShowContextMenu(const gfx::Point& p, | 386 void TreeView::ShowContextMenu(const gfx::Point& p, |
| 387 ui::MenuSourceType source_type) { | 387 ui::MenuSourceType source_type) { |
| 388 if (!model_) | 388 if (!model_) |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 611 |
| 612 int min_row = std::max(0, (min_y - kVerticalInset) / row_height_); | 612 int min_row = std::max(0, (min_y - kVerticalInset) / row_height_); |
| 613 int max_row = (max_y - kVerticalInset) / row_height_; | 613 int max_row = (max_y - kVerticalInset) / row_height_; |
| 614 if ((max_y - kVerticalInset) % row_height_ != 0) | 614 if ((max_y - kVerticalInset) % row_height_ != 0) |
| 615 max_row++; | 615 max_row++; |
| 616 int current_row = root_row(); | 616 int current_row = root_row(); |
| 617 PaintRows(canvas, min_row, max_row, &root_, root_depth(), ¤t_row); | 617 PaintRows(canvas, min_row, max_row, &root_, root_depth(), ¤t_row); |
| 618 } | 618 } |
| 619 | 619 |
| 620 void TreeView::OnFocus() { | 620 void TreeView::OnFocus() { |
| 621 GetInputMethod()->OnFocus(); | 621 if (GetInputMethod()) |
| 622 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector()); |
| 622 View::OnFocus(); | 623 View::OnFocus(); |
| 623 SchedulePaintForNode(selected_node_); | 624 SchedulePaintForNode(selected_node_); |
| 624 | 625 |
| 625 // Notify the InputMethod so that it knows to query the TextInputClient. | 626 // Notify the InputMethod so that it knows to query the TextInputClient. |
| 626 if (GetInputMethod()) | 627 if (GetInputMethod()) |
| 627 GetInputMethod()->OnCaretBoundsChanged(this); | 628 GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector()); |
| 628 } | 629 } |
| 629 | 630 |
| 630 void TreeView::OnBlur() { | 631 void TreeView::OnBlur() { |
| 631 GetInputMethod()->OnBlur(); | 632 if (GetInputMethod()) |
| 633 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); |
| 632 SchedulePaintForNode(selected_node_); | 634 SchedulePaintForNode(selected_node_); |
| 633 if (selector_) | 635 if (selector_) |
| 634 selector_->OnViewBlur(); | 636 selector_->OnViewBlur(); |
| 635 } | 637 } |
| 636 | 638 |
| 637 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { | 639 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { |
| 638 CommitEdit(); | 640 CommitEdit(); |
| 639 RequestFocus(); | 641 RequestFocus(); |
| 640 | 642 |
| 641 int row = (event.y() - kVerticalInset) / row_height_; | 643 int row = (event.y() - kVerticalInset) / row_height_; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 DCHECK(internal_node); | 998 DCHECK(internal_node); |
| 997 if (!internal_node->is_expanded()) { | 999 if (!internal_node->is_expanded()) { |
| 998 if (!internal_node->loaded_children()) | 1000 if (!internal_node->loaded_children()) |
| 999 LoadChildren(internal_node); | 1001 LoadChildren(internal_node); |
| 1000 internal_node->set_is_expanded(true); | 1002 internal_node->set_is_expanded(true); |
| 1001 return_value = true; | 1003 return_value = true; |
| 1002 } | 1004 } |
| 1003 return return_value; | 1005 return return_value; |
| 1004 } | 1006 } |
| 1005 | 1007 |
| 1008 PrefixSelector* TreeView::GetPrefixSelector() { |
| 1009 if (!selector_) |
| 1010 selector_.reset(new PrefixSelector(this)); |
| 1011 return selector_.get(); |
| 1012 } |
| 1013 |
| 1006 // InternalNode ---------------------------------------------------------------- | 1014 // InternalNode ---------------------------------------------------------------- |
| 1007 | 1015 |
| 1008 TreeView::InternalNode::InternalNode() | 1016 TreeView::InternalNode::InternalNode() |
| 1009 : model_node_(NULL), | 1017 : model_node_(NULL), |
| 1010 loaded_children_(false), | 1018 loaded_children_(false), |
| 1011 is_expanded_(false), | 1019 is_expanded_(false), |
| 1012 text_width_(0) { | 1020 text_width_(0) { |
| 1013 } | 1021 } |
| 1014 | 1022 |
| 1015 TreeView::InternalNode::~InternalNode() { | 1023 TreeView::InternalNode::~InternalNode() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1036 if (!is_expanded_) | 1044 if (!is_expanded_) |
| 1037 return max_width; | 1045 return max_width; |
| 1038 for (int i = 0; i < child_count(); ++i) { | 1046 for (int i = 0; i < child_count(); ++i) { |
| 1039 max_width = std::max(max_width, | 1047 max_width = std::max(max_width, |
| 1040 GetChild(i)->GetMaxWidth(indent, depth + 1)); | 1048 GetChild(i)->GetMaxWidth(indent, depth + 1)); |
| 1041 } | 1049 } |
| 1042 return max_width; | 1050 return max_width; |
| 1043 } | 1051 } |
| 1044 | 1052 |
| 1045 } // namespace views | 1053 } // namespace views |
| OLD | NEW |