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

Side by Side Diff: views/focus/focus_manager_unittest.cc

Issue 6881107: Rework the way Widget::Init works: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
« no previous file with comments | « views/examples/widget_example.cc ('k') | views/view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 283
284 virtual FocusTraversable* GetFocusTraversable() { 284 virtual FocusTraversable* GetFocusTraversable() {
285 return widget_->GetRootView(); 285 return widget_->GetRootView();
286 } 286 }
287 287
288 virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child) { 288 virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child) {
289 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); 289 NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
290 290
291 if (child == this && is_add) { 291 if (child == this && is_add) {
292 if (!widget_) { 292 if (!widget_) {
293 widget_ = Widget::CreateWidget( 293 widget_ = Widget::CreateWidget();
294 Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); 294 Widget::CreateParams params(Widget::CreateParams::TYPE_CONTROL);
295 #if defined(OS_WIN) 295 #if defined(OS_WIN)
296 gfx::NativeView parent_native_view = 296 params.parent = parent->GetRootView()->GetWidget()->GetNativeView();
297 parent->GetRootView()->GetWidget()->GetNativeView();
298 #elif defined(TOOLKIT_USES_GTK) 297 #elif defined(TOOLKIT_USES_GTK)
299 gfx::NativeView parent_native_view = native_view(); 298 params.parent = native_view();
300 #endif 299 #endif
301 widget_->Init(parent_native_view, gfx::Rect(0, 0, 0, 0)); 300 widget_->Init(params);
302 widget_->SetFocusTraversableParentView(this); 301 widget_->SetFocusTraversableParentView(this);
303 widget_->SetContentsView(child_); 302 widget_->SetContentsView(child_);
304 } 303 }
305 304
306 // We have been added to a view hierarchy, attach the native view. 305 // We have been added to a view hierarchy, attach the native view.
307 Attach(widget_->GetNativeView()); 306 Attach(widget_->GetNativeView());
308 // Also update the FocusTraversable parent so the focus traversal works. 307 // Also update the FocusTraversable parent so the focus traversal works.
309 widget_->GetRootView()->SetFocusTraversableParent( 308 widget_->GetRootView()->SetFocusTraversableParent(
310 GetWidget()->GetFocusTraversable()); 309 GetWidget()->GetFocusTraversable());
311 } 310 }
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 ATOM atom = RegisterClassEx(&class_ex); 1595 ATOM atom = RegisterClassEx(&class_ex);
1597 ASSERT_TRUE(atom); 1596 ASSERT_TRUE(atom);
1598 1597
1599 // Create a native dialog window. 1598 // Create a native dialog window.
1600 HWND hwnd = CreateWindowEx(0, class_ex.lpszClassName, NULL, 1599 HWND hwnd = CreateWindowEx(0, class_ex.lpszClassName, NULL,
1601 WS_OVERLAPPEDWINDOW, 0, 0, 200, 200, 1600 WS_OVERLAPPEDWINDOW, 0, 0, 200, 200,
1602 NULL, NULL, NULL, NULL); 1601 NULL, NULL, NULL, NULL);
1603 ASSERT_TRUE(hwnd); 1602 ASSERT_TRUE(hwnd);
1604 1603
1605 // Create a view window parented to native dialog. 1604 // Create a view window parented to native dialog.
1606 WidgetWin widget1; 1605 scoped_ptr<Widget> widget1(Widget::CreateWidget());
1607 Widget::CreateParams params(Widget::CreateParams::TYPE_CONTROL); 1606 Widget::CreateParams params(Widget::CreateParams::TYPE_CONTROL);
1608 params.delete_on_destroy = false; 1607 params.delete_on_destroy = false;
1609 widget1.SetCreateParams(params); 1608 params.parent = hwnd;
1610 widget1.set_window_style(WS_CHILD); 1609 params.bounds = gfx::Rect(0, 0, 100, 100);
1611 widget1.Init(hwnd, gfx::Rect(0, 0, 100, 100)); 1610 widget1->Init(params);
1612 1611
1613 // Get the focus manager directly from the first window. Should exist 1612 // Get the focus manager directly from the first window. Should exist
1614 // because the first window is the root widget. 1613 // because the first window is the root widget.
1615 views::FocusManager* focus_manager_member1 = widget1.GetFocusManager(); 1614 views::FocusManager* focus_manager_member1 = widget1->GetFocusManager();
1616 EXPECT_TRUE(focus_manager_member1); 1615 EXPECT_TRUE(focus_manager_member1);
1617 1616
1618 // Create another view window parented to the first view window. 1617 // Create another view window parented to the first view window.
1619 WidgetWin widget2; 1618 scoped_ptr<Widget> widget2(Widget::CreateWidget());
1620 widget2.SetCreateParams(params); 1619 params.parent = widget1->GetNativeView();
1621 widget2.Init(widget1.GetNativeView(), gfx::Rect(0, 0, 100, 100)); 1620 widget2->Init(params);
1622 1621
1623 // Get the focus manager directly from the second window. Should return the 1622 // Get the focus manager directly from the second window. Should return the
1624 // first window's focus manager. 1623 // first window's focus manager.
1625 views::FocusManager* focus_manager_member2 = widget2.GetFocusManager(); 1624 views::FocusManager* focus_manager_member2 = widget2->GetFocusManager();
1626 EXPECT_EQ(focus_manager_member2, focus_manager_member1); 1625 EXPECT_EQ(focus_manager_member2, focus_manager_member1);
1627 1626
1628 // Get the focus manager indirectly using the first window handle. Should 1627 // Get the focus manager indirectly using the first window handle. Should
1629 // return the first window's focus manager. 1628 // return the first window's focus manager.
1630 views::FocusManager* focus_manager_indirect = 1629 views::FocusManager* focus_manager_indirect =
1631 views::FocusManager::GetFocusManagerForNativeView( 1630 views::FocusManager::GetFocusManagerForNativeView(
1632 widget1.GetNativeView()); 1631 widget1->GetNativeView());
1633 EXPECT_EQ(focus_manager_indirect, focus_manager_member1); 1632 EXPECT_EQ(focus_manager_indirect, focus_manager_member1);
1634 1633
1635 // Get the focus manager indirectly using the second window handle. Should 1634 // Get the focus manager indirectly using the second window handle. Should
1636 // return the first window's focus manager. 1635 // return the first window's focus manager.
1637 focus_manager_indirect = 1636 focus_manager_indirect =
1638 views::FocusManager::GetFocusManagerForNativeView( 1637 views::FocusManager::GetFocusManagerForNativeView(
1639 widget2.GetNativeView()); 1638 widget2->GetNativeView());
1640 EXPECT_EQ(focus_manager_indirect, focus_manager_member1); 1639 EXPECT_EQ(focus_manager_indirect, focus_manager_member1);
1641 1640
1642 DestroyWindow(hwnd); 1641 DestroyWindow(hwnd);
1643 } 1642 }
1644 #endif 1643 #endif
1645 1644
1646 #if defined(OS_CHROMEOS) 1645 #if defined(OS_CHROMEOS)
1647 class FocusManagerDtorTest : public FocusManagerTest { 1646 class FocusManagerDtorTest : public FocusManagerTest {
1648 protected: 1647 protected:
1649 typedef std::vector<std::string> DtorTrackVector; 1648 typedef std::vector<std::string> DtorTrackVector;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 // Focus manager should be the last one to destruct. 1735 // Focus manager should be the last one to destruct.
1737 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); 1736 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str());
1738 1737
1739 // Clear window_ so that we don't try to close it again. 1738 // Clear window_ so that we don't try to close it again.
1740 window_ = NULL; 1739 window_ = NULL;
1741 } 1740 }
1742 1741
1743 #endif // defined(OS_CHROMEOS) 1742 #endif // defined(OS_CHROMEOS)
1744 1743
1745 } // namespace views 1744 } // namespace views
OLDNEW
« no previous file with comments | « views/examples/widget_example.cc ('k') | views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698