| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 CancelEdit(); | 363 CancelEdit(); |
| 364 RequestFocus(); | 364 RequestFocus(); |
| 365 } | 365 } |
| 366 return true; | 366 return true; |
| 367 } | 367 } |
| 368 | 368 |
| 369 bool TreeView::OnMousePressed(const ui::MouseEvent& event) { | 369 bool TreeView::OnMousePressed(const ui::MouseEvent& event) { |
| 370 return OnClickOrTap(event); | 370 return OnClickOrTap(event); |
| 371 } | 371 } |
| 372 | 372 |
| 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) { | 373 void TreeView::OnGestureEvent(ui::GestureEvent* event) { |
| 380 if (event->type() == ui::ET_GESTURE_TAP) { | 374 if (event->type() == ui::ET_GESTURE_TAP) { |
| 381 if (OnClickOrTap(*event)) | 375 if (OnClickOrTap(*event)) |
| 382 event->SetHandled(); | 376 event->SetHandled(); |
| 383 } | 377 } |
| 384 } | 378 } |
| 385 | 379 |
| 386 void TreeView::ShowContextMenu(const gfx::Point& p, | 380 void TreeView::ShowContextMenu(const gfx::Point& p, |
| 387 ui::MenuSourceType source_type) { | 381 ui::MenuSourceType source_type) { |
| 388 if (!model_) | 382 if (!model_) |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 605 |
| 612 int min_row = std::max(0, (min_y - kVerticalInset) / row_height_); | 606 int min_row = std::max(0, (min_y - kVerticalInset) / row_height_); |
| 613 int max_row = (max_y - kVerticalInset) / row_height_; | 607 int max_row = (max_y - kVerticalInset) / row_height_; |
| 614 if ((max_y - kVerticalInset) % row_height_ != 0) | 608 if ((max_y - kVerticalInset) % row_height_ != 0) |
| 615 max_row++; | 609 max_row++; |
| 616 int current_row = root_row(); | 610 int current_row = root_row(); |
| 617 PaintRows(canvas, min_row, max_row, &root_, root_depth(), ¤t_row); | 611 PaintRows(canvas, min_row, max_row, &root_, root_depth(), ¤t_row); |
| 618 } | 612 } |
| 619 | 613 |
| 620 void TreeView::OnFocus() { | 614 void TreeView::OnFocus() { |
| 621 GetInputMethod()->OnFocus(); | 615 if (GetInputMethod()) |
| 616 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector()); |
| 622 View::OnFocus(); | 617 View::OnFocus(); |
| 623 SchedulePaintForNode(selected_node_); | 618 SchedulePaintForNode(selected_node_); |
| 624 | 619 |
| 625 // Notify the InputMethod so that it knows to query the TextInputClient. | 620 // Notify the InputMethod so that it knows to query the TextInputClient. |
| 626 if (GetInputMethod()) | 621 if (GetInputMethod()) |
| 627 GetInputMethod()->OnCaretBoundsChanged(this); | 622 GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector()); |
| 628 } | 623 } |
| 629 | 624 |
| 630 void TreeView::OnBlur() { | 625 void TreeView::OnBlur() { |
| 631 GetInputMethod()->OnBlur(); | 626 if (GetInputMethod()) |
| 627 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); |
| 632 SchedulePaintForNode(selected_node_); | 628 SchedulePaintForNode(selected_node_); |
| 633 if (selector_) | 629 if (selector_) |
| 634 selector_->OnViewBlur(); | 630 selector_->OnViewBlur(); |
| 635 } | 631 } |
| 636 | 632 |
| 637 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { | 633 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { |
| 638 CommitEdit(); | 634 CommitEdit(); |
| 639 RequestFocus(); | 635 RequestFocus(); |
| 640 | 636 |
| 641 int row = (event.y() - kVerticalInset) / row_height_; | 637 int row = (event.y() - kVerticalInset) / row_height_; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 DCHECK(internal_node); | 992 DCHECK(internal_node); |
| 997 if (!internal_node->is_expanded()) { | 993 if (!internal_node->is_expanded()) { |
| 998 if (!internal_node->loaded_children()) | 994 if (!internal_node->loaded_children()) |
| 999 LoadChildren(internal_node); | 995 LoadChildren(internal_node); |
| 1000 internal_node->set_is_expanded(true); | 996 internal_node->set_is_expanded(true); |
| 1001 return_value = true; | 997 return_value = true; |
| 1002 } | 998 } |
| 1003 return return_value; | 999 return return_value; |
| 1004 } | 1000 } |
| 1005 | 1001 |
| 1002 PrefixSelector* TreeView::GetPrefixSelector() { |
| 1003 if (!selector_) |
| 1004 selector_.reset(new PrefixSelector(this)); |
| 1005 return selector_.get(); |
| 1006 } |
| 1007 |
| 1006 // InternalNode ---------------------------------------------------------------- | 1008 // InternalNode ---------------------------------------------------------------- |
| 1007 | 1009 |
| 1008 TreeView::InternalNode::InternalNode() | 1010 TreeView::InternalNode::InternalNode() |
| 1009 : model_node_(NULL), | 1011 : model_node_(NULL), |
| 1010 loaded_children_(false), | 1012 loaded_children_(false), |
| 1011 is_expanded_(false), | 1013 is_expanded_(false), |
| 1012 text_width_(0) { | 1014 text_width_(0) { |
| 1013 } | 1015 } |
| 1014 | 1016 |
| 1015 TreeView::InternalNode::~InternalNode() { | 1017 TreeView::InternalNode::~InternalNode() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1036 if (!is_expanded_) | 1038 if (!is_expanded_) |
| 1037 return max_width; | 1039 return max_width; |
| 1038 for (int i = 0; i < child_count(); ++i) { | 1040 for (int i = 0; i < child_count(); ++i) { |
| 1039 max_width = std::max(max_width, | 1041 max_width = std::max(max_width, |
| 1040 GetChild(i)->GetMaxWidth(indent, depth + 1)); | 1042 GetChild(i)->GetMaxWidth(indent, depth + 1)); |
| 1041 } | 1043 } |
| 1042 return max_width; | 1044 return max_width; |
| 1043 } | 1045 } |
| 1044 | 1046 |
| 1045 } // namespace views | 1047 } // namespace views |
| OLD | NEW |