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

Side by Side Diff: ui/views/cocoa/bridged_native_widget.mm

Issue 329463002: MacViews: Implement text input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More changes for tapted. Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ui/views/cocoa/bridged_native_widget.h" 5 #import "ui/views/cocoa/bridged_native_widget.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/base/ime/input_method.h" 8 #include "ui/base/ime/input_method.h"
9 #include "ui/base/ime/input_method_factory.h" 9 #include "ui/base/ime/input_method_factory.h"
10 #include "ui/base/ui_base_switches_util.h" 10 #include "ui/base/ui_base_switches_util.h"
11 #import "ui/views/cocoa/bridged_content_view.h" 11 #import "ui/views/cocoa/bridged_content_view.h"
12 #import "ui/views/cocoa/views_nswindow_delegate.h" 12 #import "ui/views/cocoa/views_nswindow_delegate.h"
13 #include "ui/views/ime/input_method_bridge.h" 13 #include "ui/views/ime/input_method_bridge.h"
14 #include "ui/views/ime/null_input_method.h" 14 #include "ui/views/ime/null_input_method.h"
15 #include "ui/views/view.h" 15 #include "ui/views/view.h"
16 #include "ui/views/widget/native_widget_mac.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 18
18 namespace views { 19 namespace views {
19 20
20 BridgedNativeWidget::BridgedNativeWidget(NativeWidgetMac* parent) 21 BridgedNativeWidget::BridgedNativeWidget(NativeWidgetMac* parent)
21 : native_widget_mac_(parent) { 22 : native_widget_mac_(parent) {
22 window_delegate_.reset( 23 window_delegate_.reset(
23 [[ViewsNSWindowDelegate alloc] initWithBridgedNativeWidget:this]); 24 [[ViewsNSWindowDelegate alloc] initWithBridgedNativeWidget:this]);
25 focus_manager_ = parent ? parent->GetWidget()->GetFocusManager() : NULL;
26 if (focus_manager_)
27 focus_manager_->AddFocusChangeListener(this);
24 } 28 }
25 29
26 BridgedNativeWidget::~BridgedNativeWidget() { 30 BridgedNativeWidget::~BridgedNativeWidget() {
31 if (focus_manager_)
32 focus_manager_->RemoveFocusChangeListener(this);
27 SetRootView(NULL); 33 SetRootView(NULL);
28 [window_ setDelegate:nil]; 34 [window_ setDelegate:nil];
29 } 35 }
30 36
31 void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window) { 37 void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window) {
32 DCHECK(!window_); 38 DCHECK(!window_);
33 window_.swap(window); 39 window_.swap(window);
34 [window_ setDelegate:window_delegate_]; 40 [window_ setDelegate:window_delegate_];
35 } 41 }
36 42
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 74 }
69 return input_method_.get(); 75 return input_method_.get();
70 } 76 }
71 77
72 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////
73 // BridgedNativeWidget, internal::InputMethodDelegate: 79 // BridgedNativeWidget, internal::InputMethodDelegate:
74 80
75 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { 81 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
76 // Mac key events don't go through this, but some unit tests that use 82 // Mac key events don't go through this, but some unit tests that use
77 // MockInputMethod do. 83 // MockInputMethod do.
78 Widget* widget = [bridged_view_ hostedView]->GetWidget(); 84 Widget* widget = [bridged_view_ hostedView]->GetWidget();
tapted 2014/06/20 00:40:59 I'd probably do DCHECK(parent_); DCHECK(focus_man
Andre 2014/06/20 01:00:39 Done.
79 widget->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); 85 widget->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
80 if (!key.handled() && widget->GetFocusManager()) 86 if (!key.handled() && focus_manager_)
81 widget->GetFocusManager()->OnKeyEvent(key); 87 focus_manager_->OnKeyEvent(key);
88 }
89
90 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before,
91 View* focused_now) {
92 }
93
94 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before,
95 View* focused_now) {
96 ui::TextInputClient* input_client =
97 focused_now ? focused_now->GetTextInputClient() : NULL;
98 [bridged_view_ setTextInputClient:input_client];
82 } 99 }
83 100
84 } // namespace views 101 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698