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

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

Powered by Google App Engine
This is Rietveld 408576698