Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: ui/views/controls/tree/tree_view.cc

Issue 1177503003: Remove the 2-level input method system & InputMethodBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: per comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 GetInputMethod()->DetachTextInputClient(selector_.get());
101
98 if (focus_manager_) { 102 if (focus_manager_) {
99 focus_manager_->RemoveFocusChangeListener(this); 103 focus_manager_->RemoveFocusChangeListener(this);
100 focus_manager_ = NULL; 104 focus_manager_ = NULL;
101 } 105 }
102 } 106 }
103 107
104 View* TreeView::CreateParentIfNecessary() { 108 View* TreeView::CreateParentIfNecessary() {
105 ScrollView* scroll_view = ScrollView::CreateScrollViewWithBorder(); 109 ScrollView* scroll_view = ScrollView::CreateScrollViewWithBorder();
106 scroll_view->SetContents(this); 110 scroll_view->SetContents(this);
107 return scroll_view; 111 return scroll_view;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 CancelEdit(); 367 CancelEdit();
364 RequestFocus(); 368 RequestFocus();
365 } 369 }
366 return true; 370 return true;
367 } 371 }
368 372
369 bool TreeView::OnMousePressed(const ui::MouseEvent& event) { 373 bool TreeView::OnMousePressed(const ui::MouseEvent& event) {
370 return OnClickOrTap(event); 374 return OnClickOrTap(event);
371 } 375 }
372 376
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) { 377 void TreeView::OnGestureEvent(ui::GestureEvent* event) {
380 if (event->type() == ui::ET_GESTURE_TAP) { 378 if (event->type() == ui::ET_GESTURE_TAP) {
381 if (OnClickOrTap(*event)) 379 if (OnClickOrTap(*event))
382 event->SetHandled(); 380 event->SetHandled();
383 } 381 }
384 } 382 }
385 383
386 void TreeView::ShowContextMenu(const gfx::Point& p, 384 void TreeView::ShowContextMenu(const gfx::Point& p,
387 ui::MenuSourceType source_type) { 385 ui::MenuSourceType source_type) {
388 if (!model_) 386 if (!model_)
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 609
612 int min_row = std::max(0, (min_y - kVerticalInset) / row_height_); 610 int min_row = std::max(0, (min_y - kVerticalInset) / row_height_);
613 int max_row = (max_y - kVerticalInset) / row_height_; 611 int max_row = (max_y - kVerticalInset) / row_height_;
614 if ((max_y - kVerticalInset) % row_height_ != 0) 612 if ((max_y - kVerticalInset) % row_height_ != 0)
615 max_row++; 613 max_row++;
616 int current_row = root_row(); 614 int current_row = root_row();
617 PaintRows(canvas, min_row, max_row, &root_, root_depth(), &current_row); 615 PaintRows(canvas, min_row, max_row, &root_, root_depth(), &current_row);
618 } 616 }
619 617
620 void TreeView::OnFocus() { 618 void TreeView::OnFocus() {
621 GetInputMethod()->OnFocus(); 619 if (GetInputMethod())
620 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector());
622 View::OnFocus(); 621 View::OnFocus();
623 SchedulePaintForNode(selected_node_); 622 SchedulePaintForNode(selected_node_);
624 623
625 // Notify the InputMethod so that it knows to query the TextInputClient. 624 // Notify the InputMethod so that it knows to query the TextInputClient.
626 if (GetInputMethod()) 625 if (GetInputMethod())
627 GetInputMethod()->OnCaretBoundsChanged(this); 626 GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector());
628 } 627 }
629 628
630 void TreeView::OnBlur() { 629 void TreeView::OnBlur() {
631 GetInputMethod()->OnBlur(); 630 if (GetInputMethod())
631 GetInputMethod()->DetachTextInputClient(GetPrefixSelector());
632 SchedulePaintForNode(selected_node_); 632 SchedulePaintForNode(selected_node_);
633 if (selector_) 633 if (selector_)
634 selector_->OnViewBlur(); 634 selector_->OnViewBlur();
635 } 635 }
636 636
637 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) { 637 bool TreeView::OnClickOrTap(const ui::LocatedEvent& event) {
638 CommitEdit(); 638 CommitEdit();
639 RequestFocus(); 639 RequestFocus();
640 640
641 int row = (event.y() - kVerticalInset) / row_height_; 641 int row = (event.y() - kVerticalInset) / row_height_;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 DCHECK(internal_node); 996 DCHECK(internal_node);
997 if (!internal_node->is_expanded()) { 997 if (!internal_node->is_expanded()) {
998 if (!internal_node->loaded_children()) 998 if (!internal_node->loaded_children())
999 LoadChildren(internal_node); 999 LoadChildren(internal_node);
1000 internal_node->set_is_expanded(true); 1000 internal_node->set_is_expanded(true);
1001 return_value = true; 1001 return_value = true;
1002 } 1002 }
1003 return return_value; 1003 return return_value;
1004 } 1004 }
1005 1005
1006 PrefixSelector* TreeView::GetPrefixSelector() {
1007 if (!selector_)
1008 selector_.reset(new PrefixSelector(this));
1009 return selector_.get();
1010 }
1011
1006 // InternalNode ---------------------------------------------------------------- 1012 // InternalNode ----------------------------------------------------------------
1007 1013
1008 TreeView::InternalNode::InternalNode() 1014 TreeView::InternalNode::InternalNode()
1009 : model_node_(NULL), 1015 : model_node_(NULL),
1010 loaded_children_(false), 1016 loaded_children_(false),
1011 is_expanded_(false), 1017 is_expanded_(false),
1012 text_width_(0) { 1018 text_width_(0) {
1013 } 1019 }
1014 1020
1015 TreeView::InternalNode::~InternalNode() { 1021 TreeView::InternalNode::~InternalNode() {
(...skipping 20 matching lines...) Expand all
1036 if (!is_expanded_) 1042 if (!is_expanded_)
1037 return max_width; 1043 return max_width;
1038 for (int i = 0; i < child_count(); ++i) { 1044 for (int i = 0; i < child_count(); ++i) {
1039 max_width = std::max(max_width, 1045 max_width = std::max(max_width,
1040 GetChild(i)->GetMaxWidth(indent, depth + 1)); 1046 GetChild(i)->GetMaxWidth(indent, depth + 1));
1041 } 1047 }
1042 return max_width; 1048 return max_width;
1043 } 1049 }
1044 1050
1045 } // namespace views 1051 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698