OLD | NEW |
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 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
10 #import "base/mac/mac_util.h" | 10 #import "base/mac/mac_util.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 return bridge_; | 77 return bridge_; |
78 } | 78 } |
79 | 79 |
80 // internal::NativeWidgetPrivate: | 80 // internal::NativeWidgetPrivate: |
81 void InitNativeWidget(const Widget::InitParams& params) override { | 81 void InitNativeWidget(const Widget::InitParams& params) override { |
82 ownership_ = params.ownership; | 82 ownership_ = params.ownership; |
83 | 83 |
84 // Usually the bridge gets initialized here. It is skipped to run extra | 84 // Usually the bridge gets initialized here. It is skipped to run extra |
85 // checks in tests, and so that a second window isn't created. | 85 // checks in tests, and so that a second window isn't created. |
86 delegate()->OnNativeWidgetCreated(true); | 86 delegate()->OnNativeWidgetCreated(true); |
| 87 |
| 88 // To allow events to dispatch to a view, it needs a way to get focus. |
| 89 bridge_->SetFocusManager(GetWidget()->GetFocusManager()); |
87 } | 90 } |
88 | 91 |
89 void ReorderNativeViews() override { | 92 void ReorderNativeViews() override { |
90 // Called via Widget::Init to set the content view. No-op in these tests. | 93 // Called via Widget::Init to set the content view. No-op in these tests. |
91 } | 94 } |
92 | 95 |
93 private: | 96 private: |
94 DISALLOW_COPY_AND_ASSIGN(MockNativeWidgetMac); | 97 DISALLOW_COPY_AND_ASSIGN(MockNativeWidgetMac); |
95 }; | 98 }; |
96 | 99 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 std::string GetText(); | 146 std::string GetText(); |
144 | 147 |
145 // testing::Test: | 148 // testing::Test: |
146 void SetUp() override; | 149 void SetUp() override; |
147 void TearDown() override; | 150 void TearDown() override; |
148 | 151 |
149 protected: | 152 protected: |
150 scoped_ptr<views::View> view_; | 153 scoped_ptr<views::View> view_; |
151 scoped_ptr<BridgedNativeWidget> bridge_; | 154 scoped_ptr<BridgedNativeWidget> bridge_; |
152 BridgedContentView* ns_view_; // Weak. Owned by bridge_. | 155 BridgedContentView* ns_view_; // Weak. Owned by bridge_. |
| 156 base::MessageLoopForUI message_loop_; |
153 | 157 |
154 private: | 158 private: |
155 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); | 159 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); |
156 }; | 160 }; |
157 | 161 |
158 BridgedNativeWidgetTest::BridgedNativeWidgetTest() { | 162 BridgedNativeWidgetTest::BridgedNativeWidgetTest() { |
159 } | 163 } |
160 | 164 |
161 BridgedNativeWidgetTest::~BridgedNativeWidgetTest() { | 165 BridgedNativeWidgetTest::~BridgedNativeWidgetTest() { |
162 } | 166 } |
163 | 167 |
164 void BridgedNativeWidgetTest::InstallTextField(const std::string& text) { | 168 void BridgedNativeWidgetTest::InstallTextField(const std::string& text) { |
165 Textfield* textfield = new Textfield(); | 169 Textfield* textfield = new Textfield(); |
166 textfield->SetText(ASCIIToUTF16(text)); | 170 textfield->SetText(ASCIIToUTF16(text)); |
167 view_->AddChildView(textfield); | 171 view_->AddChildView(textfield); |
| 172 |
| 173 // Request focus so the InputMethod can dispatch events to the RootView, and |
| 174 // have them delivered to the textfield. Note that focusing a textfield |
| 175 // schedules a task to flash the cursor, so this requires |message_loop_|. |
| 176 textfield->RequestFocus(); |
| 177 |
168 [ns_view_ setTextInputClient:textfield]; | 178 [ns_view_ setTextInputClient:textfield]; |
169 } | 179 } |
170 | 180 |
171 std::string BridgedNativeWidgetTest::GetText() { | 181 std::string BridgedNativeWidgetTest::GetText() { |
172 NSRange range = NSMakeRange(0, NSUIntegerMax); | 182 NSRange range = NSMakeRange(0, NSUIntegerMax); |
173 NSAttributedString* text = | 183 NSAttributedString* text = |
174 [ns_view_ attributedSubstringForProposedRange:range actualRange:NULL]; | 184 [ns_view_ attributedSubstringForProposedRange:range actualRange:NULL]; |
175 return SysNSStringToUTF8([text string]); | 185 return SysNSStringToUTF8([text string]); |
176 } | 186 } |
177 | 187 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 [center postNotificationName:NSWindowDidExitFullScreenNotification | 509 [center postNotificationName:NSWindowDidExitFullScreenNotification |
500 object:window]; | 510 object:window]; |
501 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 511 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
502 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 512 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
503 | 513 |
504 widget_->CloseNow(); | 514 widget_->CloseNow(); |
505 } | 515 } |
506 | 516 |
507 } // namespace test | 517 } // namespace test |
508 } // namespace views | 518 } // namespace views |
OLD | NEW |