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 | 27 |
28 using ui::TreeModel; | 28 using ui::TreeModel; |
29 using ui::TreeModelNode; | 29 using ui::TreeModelNode; |
30 | 30 |
31 namespace views { | 31 namespace views { |
32 | 32 |
33 // Insets around the view. | 33 // Insets around the view. |
34 static const int kHorizontalInset = 2; | 34 static const int kHorizontalInset = 2; |
35 static const int kVerticalInset = 2; | 35 static const int kVerticalInset = 2; |
36 // Padding before/after the image. | 36 // Padding before/after the image. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 kArrowRegionSize; | 91 kArrowRegionSize; |
92 } | 92 } |
93 | 93 |
94 TreeView::~TreeView() { | 94 TreeView::~TreeView() { |
95 if (model_) | 95 if (model_) |
96 model_->RemoveObserver(this); | 96 model_->RemoveObserver(this); |
97 if (focus_manager_) { | 97 if (focus_manager_) { |
98 focus_manager_->RemoveFocusChangeListener(this); | 98 focus_manager_->RemoveFocusChangeListener(this); |
99 focus_manager_ = NULL; | 99 focus_manager_ = NULL; |
100 } | 100 } |
| 101 if (selector_ && GetInputMethod()) |
| 102 GetInputMethod()->DetachTextInputClient(selector_.get()); |
101 } | 103 } |
102 | 104 |
103 View* TreeView::CreateParentIfNecessary() { | 105 View* TreeView::CreateParentIfNecessary() { |
104 ScrollView* scroll_view = ScrollView::CreateScrollViewWithBorder(); | 106 ScrollView* scroll_view = ScrollView::CreateScrollViewWithBorder(); |
105 scroll_view->SetContents(this); | 107 scroll_view->SetContents(this); |
106 return scroll_view; | 108 return scroll_view; |
107 } | 109 } |
108 | 110 |
109 void TreeView::SetModel(TreeModel* model) { | 111 void TreeView::SetModel(TreeModel* model) { |
110 if (model == model_) | 112 if (model == model_) |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 334 |
333 int TreeView::GetRowForNode(ui::TreeModelNode* node) { | 335 int TreeView::GetRowForNode(ui::TreeModelNode* node) { |
334 InternalNode* internal_node = | 336 InternalNode* internal_node = |
335 GetInternalNodeForModelNode(node, DONT_CREATE_IF_NOT_LOADED); | 337 GetInternalNodeForModelNode(node, DONT_CREATE_IF_NOT_LOADED); |
336 if (!internal_node) | 338 if (!internal_node) |
337 return -1; | 339 return -1; |
338 int depth = 0; | 340 int depth = 0; |
339 return GetRowForInternalNode(internal_node, &depth); | 341 return GetRowForInternalNode(internal_node, &depth); |
340 } | 342 } |
341 | 343 |
| 344 ui::TextInputClient* TreeView::GetTextInputClient() { |
| 345 if (!selector_) |
| 346 selector_.reset(new PrefixSelector(this)); |
| 347 return selector_.get(); |
| 348 } |
| 349 |
342 void TreeView::Layout() { | 350 void TreeView::Layout() { |
343 int width = preferred_size_.width(); | 351 int width = preferred_size_.width(); |
344 int height = preferred_size_.height(); | 352 int height = preferred_size_.height(); |
345 if (parent()) { | 353 if (parent()) { |
346 width = std::max(parent()->width(), width); | 354 width = std::max(parent()->width(), width); |
347 height = std::max(parent()->height(), height); | 355 height = std::max(parent()->height(), height); |
348 } | 356 } |
349 SetBounds(x(), y(), width, height); | 357 SetBounds(x(), y(), width, height); |
350 LayoutEditor(); | 358 LayoutEditor(); |
351 } | 359 } |
(...skipping 10 matching lines...) Expand all Loading... |
362 CancelEdit(); | 370 CancelEdit(); |
363 RequestFocus(); | 371 RequestFocus(); |
364 } | 372 } |
365 return true; | 373 return true; |
366 } | 374 } |
367 | 375 |
368 bool TreeView::OnMousePressed(const ui::MouseEvent& event) { | 376 bool TreeView::OnMousePressed(const ui::MouseEvent& event) { |
369 return OnClickOrTap(event); | 377 return OnClickOrTap(event); |
370 } | 378 } |
371 | 379 |
372 ui::TextInputClient* TreeView::GetTextInputClient() { | |
373 if (!selector_) | |
374 selector_.reset(new PrefixSelector(this)); | |
375 return selector_.get(); | |
376 } | |
377 | |
378 void TreeView::OnGestureEvent(ui::GestureEvent* event) { | 380 void TreeView::OnGestureEvent(ui::GestureEvent* event) { |
379 if (event->type() == ui::ET_GESTURE_TAP) { | 381 if (event->type() == ui::ET_GESTURE_TAP) { |
380 if (OnClickOrTap(*event)) | 382 if (OnClickOrTap(*event)) |
381 event->SetHandled(); | 383 event->SetHandled(); |
382 } | 384 } |
383 } | 385 } |
384 | 386 |
385 void TreeView::ShowContextMenu(const gfx::Point& p, | 387 void TreeView::ShowContextMenu(const gfx::Point& p, |
386 ui::MenuSourceType source_type) { | 388 ui::MenuSourceType source_type) { |
387 if (!model_) | 389 if (!model_) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 612 |
611 int min_row = std::max(0, (min_y - kVerticalInset) / row_height_); | 613 int min_row = std::max(0, (min_y - kVerticalInset) / row_height_); |
612 int max_row = (max_y - kVerticalInset) / row_height_; | 614 int max_row = (max_y - kVerticalInset) / row_height_; |
613 if ((max_y - kVerticalInset) % row_height_ != 0) | 615 if ((max_y - kVerticalInset) % row_height_ != 0) |
614 max_row++; | 616 max_row++; |
615 int current_row = root_row(); | 617 int current_row = root_row(); |
616 PaintRows(canvas, min_row, max_row, &root_, root_depth(), ¤t_row); | 618 PaintRows(canvas, min_row, max_row, &root_, root_depth(), ¤t_row); |
617 } | 619 } |
618 | 620 |
619 void TreeView::OnFocus() { | 621 void TreeView::OnFocus() { |
620 GetInputMethod()->OnFocus(); | 622 if (GetInputMethod()) |
| 623 GetInputMethod()->SetFocusedTextInputClient(GetTextInputClient()); |
621 View::OnFocus(); | 624 View::OnFocus(); |
622 SchedulePaintForNode(selected_node_); | 625 SchedulePaintForNode(selected_node_); |
623 | 626 |
624 // Notify the InputMethod so that it knows to query the TextInputClient. | 627 // Notify the InputMethod so that it knows to query the TextInputClient. |
625 if (GetInputMethod()) | 628 if (GetInputMethod()) |
626 GetInputMethod()->OnCaretBoundsChanged(this); | 629 GetInputMethod()->OnCaretBoundsChanged(GetTextInputClient()); |
627 } | 630 } |
628 | 631 |
629 void TreeView::OnBlur() { | 632 void TreeView::OnBlur() { |
630 GetInputMethod()->OnBlur(); | 633 if (GetInputMethod()) |
| 634 GetInputMethod()->DetachTextInputClient(GetTextInputClient()); |
631 SchedulePaintForNode(selected_node_); | 635 SchedulePaintForNode(selected_node_); |
632 if (selector_) | 636 if (selector_) |
633 selector_->OnViewBlur(); | 637 selector_->OnViewBlur(); |
634 } | 638 } |
635 | 639 |
636 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { | 640 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { |
637 CommitEdit(); | 641 CommitEdit(); |
638 RequestFocus(); | 642 RequestFocus(); |
639 | 643 |
640 int row = (event.y() - kVerticalInset) / row_height_; | 644 int row = (event.y() - kVerticalInset) / row_height_; |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 if (!is_expanded_) | 1039 if (!is_expanded_) |
1036 return max_width; | 1040 return max_width; |
1037 for (int i = 0; i < child_count(); ++i) { | 1041 for (int i = 0; i < child_count(); ++i) { |
1038 max_width = std::max(max_width, | 1042 max_width = std::max(max_width, |
1039 GetChild(i)->GetMaxWidth(indent, depth + 1)); | 1043 GetChild(i)->GetMaxWidth(indent, depth + 1)); |
1040 } | 1044 } |
1041 return max_width; | 1045 return max_width; |
1042 } | 1046 } |
1043 | 1047 |
1044 } // namespace views | 1048 } // namespace views |
OLD | NEW |