Commit f33b483a authored by msw@chromium.org's avatar msw@chromium.org

Reland Remove NativeTabbedPane[Win|Wrapper]; promote Views impl.

Original CL (reverted for leaks): https://codereview.chromium.org/12225042/
http://build.chromium.org/p/chromium.memory.fyi/builders/Chromium%20OS%20Heapcheck/builds/14990
http://build.chromium.org/p/chromium.memory.fyi/builders/Chromium%20OS%20%28valgrind%29%283%29/builds/22339
Leaks are fixed here by having the tabbed pane own its tab content Views.
(all Valgrind and Heapcheck leaks observed locally are fixed by this change)

TBR=sky@chromium.org

The original CL description is copied below:
========================================
Remove NativeTabbedPane[Win|Wrapper]; promote Views impl.

Remove NativeTabbedPaneWin and NativeTabbedPaneWrapper.
( its last use was eliminated in http://crrev.com/180924 )
Write a TabbedPane based on NativeTabbedPaneViews.
Update unit tests; cleanup; etc.

BUG=138059
TEST=No observable tabbed pane appearance/behavior changes (see the WebsiteSettingsPopupView and CollectedCookiesView); unit tests.
R=markusheintz@chromium.org,sky@chromium.org,ben@chromium.org

Review URL: https://chromiumcodereview.appspot.com/12211122

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181945 0039d316-1c4b-4281-b951-d872f2087c98
parent 173a9458
......@@ -293,7 +293,7 @@ void CollectedCookiesViews::Init() {
layout->StartRow(0, single_column_layout_id);
views::TabbedPane* tabbed_pane = new views::TabbedPane();
// This color matches native_tabbed_pane_views.cc's kTabBorderColor.
// This color matches tabbed_pane.cc's kTabBorderColor.
const SkColor border_color = SkColorSetRGB(0xCC, 0xCC, 0xCC);
// TODO(msw): Remove border and expand bounds in new dialog style.
tabbed_pane->set_border(views::Border::CreateSolidBorder(1, border_color));
......
......@@ -322,14 +322,12 @@ WebsiteSettingsPopupView::WebsiteSettingsPopupView(
tabbed_pane_->AddTabAtIndex(
TAB_ID_PERMISSIONS,
l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS),
CreatePermissionsTab(),
true);
CreatePermissionsTab());
connection_tab_ = CreateConnectionTab();
tabbed_pane_->AddTabAtIndex(
TAB_ID_CONNECTION,
l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION),
connection_tab_,
true);
connection_tab_);
DCHECK_EQ(tabbed_pane_->GetTabCount(), NUM_TAB_IDS);
tabbed_pane_->set_listener(this);
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_VIEWS_H_
#define UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_VIEWS_H_
#include <vector>
#include "ui/views/controls/tabbed_pane/native_tabbed_pane_wrapper.h"
#include "ui/views/view.h"
namespace views {
class TabbedPane;
class TabLayout;
class TabStrip;
class Widget;
class NativeTabbedPaneViews : public View,
public NativeTabbedPaneWrapper {
public:
explicit NativeTabbedPaneViews(TabbedPane* tabbed_pane);
virtual ~NativeTabbedPaneViews();
void TabSelectionChanged(View* selected);
// Overridden from NativeTabbedPaneWrapper:
virtual void AddTab(const string16& title, View* contents) OVERRIDE;
virtual void AddTabAtIndex(int index,
const string16& title,
View* contents,
bool select_if_first_tab) OVERRIDE;
virtual View* RemoveTabAtIndex(int index) OVERRIDE;
virtual void SelectTabAt(int index) OVERRIDE;
virtual int GetTabCount() OVERRIDE;
virtual int GetSelectedTabIndex() OVERRIDE;
virtual View* GetSelectedTab() OVERRIDE;
virtual View* GetView() OVERRIDE;
virtual void SetFocus() OVERRIDE;
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual gfx::NativeView GetTestingHandle() const OVERRIDE;
// View overrides:
virtual void Layout() OVERRIDE;
private:
void InitControl();
// Called upon creation of native control to initialize tabs that are added
// before the native control is created.
void InitializeTabs();
// Adds a tab with the given content to native control at the given index.
void AddNativeTab(int index, const string16& title);
// The tabbed-pane we are bound to.
TabbedPane* tabbed_pane_;
// The layout manager we use for managing our tabs.
TabLayout* tab_layout_manager_;
// TabStrip.
TabStrip* tab_strip_;
// The content displayed in the tab.
View* content_view_;
DISALLOW_COPY_AND_ASSIGN(NativeTabbedPaneViews);
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_VIEWS_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_WIN_H_
#define UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_WIN_H_
#include <vector>
#include "ui/views/controls/native_control_win.h"
#include "ui/views/controls/tabbed_pane/native_tabbed_pane_wrapper.h"
namespace views {
class TabbedPane;
class TabLayout;
class Widget;
class NativeTabbedPaneWin : public NativeControlWin,
public NativeTabbedPaneWrapper {
public:
explicit NativeTabbedPaneWin(TabbedPane* tabbed_pane);
virtual ~NativeTabbedPaneWin();
// NativeTabbedPaneWrapper implementation:
virtual void AddTab(const string16& title, View* contents);
virtual void AddTabAtIndex(int index,
const string16& title,
View* contents,
bool select_if_first_tab);
virtual View* RemoveTabAtIndex(int index);
virtual void SelectTabAt(int index);
virtual int GetTabCount();
virtual int GetSelectedTabIndex();
virtual View* GetSelectedTab();
virtual View* GetView();
virtual void SetFocus();
virtual gfx::Size GetPreferredSize();
virtual gfx::NativeView GetTestingHandle() const;
// NativeControlWin overrides.
virtual void CreateNativeControl();
virtual bool ProcessMessage(UINT message,
WPARAM w_param,
LPARAM l_param,
LRESULT* result);
// View overrides:
virtual void Layout();
virtual FocusTraversable* GetFocusTraversable();
virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child);
private:
// Called upon creation of native control to initialize tabs that are added
// before the native control is created.
void InitializeTabs();
// Adds a tab with the given content to native control at the given index.
void AddNativeTab(int index, const string16& title);
// Changes the contents view to the view associated with the tab at |index|.
// |invoke_listener| controls if this methold should invoke the
// Listener::TabSelectedAt callback.
void DoSelectTabAt(int index, boolean invoke_listener);
// Resizes the HWND control to macth the size of the containing view.
void ResizeContents();
// The tabbed-pane we are bound to.
TabbedPane* tabbed_pane_;
// The layout manager we use for managing our tabs.
TabLayout* tab_layout_manager_;
// The views associated with the different tabs.
std::vector<View*> tab_views_;
// The tab's title strings.
std::vector<const string16> tab_titles_;
// The index of the selected tab.
int selected_index_;
// The window displayed in the tab.
Widget* content_window_;
DISALLOW_COPY_AND_ASSIGN(NativeTabbedPaneWin);
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_WIN_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_WRAPPER_H_
#define UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_WRAPPER_H_
#include "base/string16.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
class Size;
}
namespace views {
class View;
// An interface implemented by an object that provides a platform-native
// tabbed-pane.
class NativeTabbedPaneWrapper {
public:
// The TabbedPane calls this when it is destroyed to clean up the wrapper
// object.
virtual ~NativeTabbedPaneWrapper() {}
// Adds a new tab at the end of this TabbedPane with the specified |title|.
// |contents| is the view displayed when the tab is selected and is owned by
// the TabbedPane.
virtual void AddTab(const string16& title, View* contents) = 0;
// Adds a new tab at the specified |index| with the specified |title|.
// |contents| is the view displayed when the tab is selected and is owned by
// the TabbedPane. If |select_if_first_tab| is true and the tabbed pane is
// currently empty, the new tab is selected. If you pass in false for
// |select_if_first_tab| you need to explicitly invoke SelectTabAt, otherwise
// the tabbed pane will not have a valid selection.
virtual void AddTabAtIndex(int index,
const string16& title,
View* contents,
bool select_if_first_tab) = 0;
// Removes the tab at the specified |index| and returns the associated content
// view. The caller becomes the owner of the returned view.
virtual View* RemoveTabAtIndex(int index) = 0;
// Selects the tab at the specified |index|, which must be valid.
virtual void SelectTabAt(int index) = 0;
// Returns the number of tabs.
virtual int GetTabCount() = 0;
// Returns the index of the selected tab.
virtual int GetSelectedTabIndex() = 0;
// Returns the contents of the selected tab.
virtual View* GetSelectedTab() = 0;
// Retrieves the views::View that hosts the native control.
virtual View* GetView() = 0;
// Sets the focus to the tabbed pane native view.
virtual void SetFocus() = 0;
// Gets the preferred size of the tabbed pane.
virtual gfx::Size GetPreferredSize() = 0;
// Returns a handle to the underlying native view for testing.
virtual gfx::NativeView GetTestingHandle() const = 0;
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_TABBED_PANE_NATIVE_TABBED_PANE_WRAPPER_H_
......@@ -12,8 +12,9 @@
namespace views {
class NativeTabbedPaneWrapper;
class Tab;
class TabbedPaneListener;
class TabStrip;
// TabbedPane is a view that shows tabs. When the user clicks on a tab, the
// associated view is displayed.
......@@ -24,20 +25,13 @@ class VIEWS_EXPORT TabbedPane : public View {
TabbedPaneListener* listener() const { return listener_; }
void set_listener(TabbedPaneListener* listener) { listener_ = listener; }
#if defined(OS_WIN) && !defined(USE_AURA)
bool use_native_win_control() { return use_native_win_control_; }
void set_use_native_win_control(bool use_native_win_control) {
use_native_win_control_ = use_native_win_control;
}
#endif
int selected_tab_index() const { return selected_tab_index_; }
// Returns the number of tabs.
int GetTabCount();
// Returns the index of the selected tab.
int GetSelectedTabIndex();
// Returns the contents of the selected tab.
// Returns the contents of the selected tab or NULL if there is none.
View* GetSelectedTab();
// Adds a new tab at the end of this TabbedPane with the specified |title|.
......@@ -45,62 +39,44 @@ class VIEWS_EXPORT TabbedPane : public View {
// the TabbedPane.
void AddTab(const string16& title, View* contents);
// Adds a new tab at |index| with |title|.
// |contents| is the view displayed when the tab is selected and is owned by
// the TabbedPane. If |select_if_first_tab| is true and the tabbed pane is
// currently empty, the new tab is selected. If you pass in false for
// |select_if_first_tab| you need to explicitly invoke SelectTabAt, otherwise
// the tabbed pane will not have a valid selection.
void AddTabAtIndex(int index,
const string16& title,
View* contents,
bool select_if_first_tab);
// Removes the tab at |index| and returns the associated content view.
// The caller becomes the owner of the returned view.
View* RemoveTabAtIndex(int index);
// Adds a new tab at |index| with |title|. |contents| is the view displayed
// when the tab is selected and is owned by the TabbedPane. If the tabbed pane
// is currently empty, the new tab is selected.
void AddTabAtIndex(int index, const string16& title, View* contents);
// Selects the tab at |index|, which must be valid.
void SelectTabAt(int index);
void SetAccessibleName(const string16& name);
// Selects |tab| (the tabstrip view, not its content) if it is valid.
void SelectTab(Tab* tab);
// Overridden from View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
protected:
// The object that actually implements the tabbed-pane.
// Protected for tests access.
NativeTabbedPaneWrapper* native_tabbed_pane_;
private:
// The tabbed-pane's class name.
static const char kViewClassName[];
// We support Ctrl+Tab and Ctrl+Shift+Tab to navigate tabbed option pages.
void LoadAccelerators();
// Get the Tab (the tabstrip view, not its content) at the valid |index|.
Tab* GetTabAt(int index);
// Overridden from View:
virtual void Layout() OVERRIDE;
virtual void ViewHierarchyChanged(bool is_add,
View* parent,
View* child) OVERRIDE;
// Handles Ctrl+Tab and Ctrl+Shift+Tab navigation of pages.
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
virtual std::string GetClassName() const OVERRIDE;
virtual void OnFocus() OVERRIDE;
virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
#if defined(OS_WIN) && !defined(USE_AURA)
bool use_native_win_control_;
#endif
// Our listener. Not owned. Notified when tab selection changes.
// A listener notified when tab selection changes. Weak, not owned.
TabbedPaneListener* listener_;
// The accessible name of this tabbed pane.
string16 accessible_name_;
// The tab strip and contents container. The child indices of these members
// correspond to match each Tab with its respective content View.
TabStrip* tab_strip_;
View* contents_;
// The selected tab index or -1 if invalid.
int selected_tab_index_;
DISALLOW_COPY_AND_ASSIGN(TabbedPane);
};
......
......@@ -8,11 +8,11 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace views {
namespace {
// A view for testing that takes a fixed preferred size upon construction.
class FixedSizeView : public View {
public:
......@@ -30,55 +30,18 @@ class FixedSizeView : public View {
DISALLOW_COPY_AND_ASSIGN(FixedSizeView);
};
class TabbedPaneTest : public ViewsTestBase {
public:
TabbedPaneTest() {}
void TestSizeAndLayout(TabbedPane* tabbed_pane);
void TestAddRemove(TabbedPane* tabbed_pane);
TabbedPane* tabbed_pane_; // Owned by the |widget_|'s root View.
#if defined(OS_WIN) && !defined(USE_AURA)
TabbedPane* tabbed_pane_win_; // Owned by the |widget_|'s root View.
#endif
private:
virtual void SetUp() OVERRIDE;
typedef ViewsTestBase TabbedPaneTest;
scoped_ptr<Widget> widget_;
DISALLOW_COPY_AND_ASSIGN(TabbedPaneTest);
};
void TabbedPaneTest::SetUp() {
ViewsTestBase::SetUp();
widget_.reset(new Widget());
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 100, 100);
widget_->Init(params);
tabbed_pane_ = new TabbedPane();
// In order to properly initialize the |TabbedPane| it must be added to a
// parent view (see the ViewHierarchyChanged method of the |TabbedPane|).
widget_->GetRootView()->AddChildView(tabbed_pane_);
#if defined(OS_WIN) && !defined(USE_AURA)
tabbed_pane_win_ = new TabbedPane();
tabbed_pane_win_->set_use_native_win_control(true);
widget_->GetRootView()->AddChildView(tabbed_pane_win_);
#endif
}
void TabbedPaneTest::TestSizeAndLayout(TabbedPane* tabbed_pane) {
// Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout().
TEST_F(TabbedPaneTest, SizeAndLayout) {
scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane());
View* child1 = new FixedSizeView(gfx::Size(20, 10));
tabbed_pane->AddTab(ASCIIToUTF16("tab1"), child1);
View* child2 = new FixedSizeView(gfx::Size(5, 5));
tabbed_pane->AddTab(ASCIIToUTF16("tab2"), child2);
tabbed_pane->SelectTabAt(0);
// The |tabbed_pane_| implementation of Views has no border by default.
// The |tabbed_pane| implementation of Views has no border by default.
// Therefore it should be as wide as the widest tab. The native Windows
// tabbed pane has a border that used up extra space. Therefore the preferred
// width is larger than the largest child.
......@@ -91,8 +54,8 @@ void TabbedPaneTest::TestSizeAndLayout(TabbedPane* tabbed_pane) {
RunPendingMessages();
gfx::Rect bounds(child1->bounds());
EXPECT_GT(bounds.width(), 0);
// The |tabbed_pane_| has no border. Therefore the children should be as wide
// as the |tabbed_pane_|.
// The |tabbed_pane| has no border. Therefore the children should be as wide
// as the |tabbed_pane|.
EXPECT_LE(bounds.width(), 100);
EXPECT_GT(bounds.height(), 0);
EXPECT_LT(bounds.height(), 200);
......@@ -100,84 +63,31 @@ void TabbedPaneTest::TestSizeAndLayout(TabbedPane* tabbed_pane) {
// If we switch to the other tab, it should get assigned the same bounds.
tabbed_pane->SelectTabAt(1);
EXPECT_EQ(bounds, child2->bounds());
// Clean up.
delete tabbed_pane->RemoveTabAtIndex(0);
EXPECT_EQ(1, tabbed_pane->GetTabCount());
delete tabbed_pane->RemoveTabAtIndex(0);
EXPECT_EQ(0, tabbed_pane->GetTabCount());
}
void TabbedPaneTest::TestAddRemove(TabbedPane* tabbed_pane) {
View* tab0 = new View;
tabbed_pane->AddTab(ASCIIToUTF16("tab0"), tab0);
EXPECT_EQ(tab0, tabbed_pane->GetSelectedTab());
EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex());
// Add more 3 tabs.
tabbed_pane->AddTab(ASCIIToUTF16("tab1"), new View);
tabbed_pane->AddTab(ASCIIToUTF16("tab2"), new View);
tabbed_pane->AddTab(ASCIIToUTF16("tab3"), new View);
EXPECT_EQ(4, tabbed_pane->GetTabCount());
// Note: AddTab() doesn't select a tab if the tabbed pane isn't empty.
// Select the last one.
tabbed_pane->SelectTabAt(tabbed_pane->GetTabCount() - 1);
EXPECT_EQ(3, tabbed_pane->GetSelectedTabIndex());
// Remove the last one.
delete tabbed_pane->RemoveTabAtIndex(3);
EXPECT_EQ(3, tabbed_pane->GetTabCount());
// After removing the last tab, check if the tabbed pane selected the previous
// tab.
EXPECT_EQ(2, tabbed_pane->GetSelectedTabIndex());
tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab4"), new View, true);
// Assert that even adding a new tab, the tabbed pane doesn't change the
// selection, i.e., it doesn't select the new one.
// The last tab should remains selected, instead of the tab added at index 0.
EXPECT_EQ(3, tabbed_pane->GetSelectedTabIndex());
TEST_F(TabbedPaneTest, AddAndSelect) {
scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane());
// Add several tabs; only the first should be a selected automatically.
for (int i = 0; i < 3; ++i) {
View* tab = new View();
tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab);
EXPECT_EQ(i + 1, tabbed_pane->GetTabCount());
EXPECT_EQ(0, tabbed_pane->selected_tab_index());
}
// Now change the selected tab.
tabbed_pane->SelectTabAt(1);
EXPECT_EQ(1, tabbed_pane->GetSelectedTabIndex());
// Remove the first one.
delete tabbed_pane->RemoveTabAtIndex(0);
EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex());
// Clean up the other panes.
EXPECT_EQ(3, tabbed_pane->GetTabCount());
delete tabbed_pane->RemoveTabAtIndex(0);
delete tabbed_pane->RemoveTabAtIndex(0);
delete tabbed_pane->RemoveTabAtIndex(0);
EXPECT_EQ(0, tabbed_pane->GetTabCount());
}
// Select each tab.
for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) {
tabbed_pane->SelectTabAt(i);
EXPECT_EQ(i, tabbed_pane->selected_tab_index());
}
// Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout().
TEST_F(TabbedPaneTest, SizeAndLayout) {
TestSizeAndLayout(tabbed_pane_);
// TODO(markusheintz): Once replacing NativeTabbedPaneWin with
// NativeTabbedPaneView is completed (http://crbug.com/138059), then the
// TestSizeAndLayout method should be inlined here again and the "ifdef" part
// should be deleted.
#if defined(OS_WIN) && !defined(USE_AURA)
TestSizeAndLayout(tabbed_pane_win_);
#endif
// Add a tab at index 0, it should not be selected automatically.
View* tab0 = new View();
tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0);
EXPECT_NE(tab0, tabbed_pane->GetSelectedTab());
EXPECT_NE(0, tabbed_pane->selected_tab_index());
}
TEST_F(TabbedPaneTest, AddRemove) {
TestAddRemove(tabbed_pane_);
// TODO(markusheintz): Once replacing NativeTabbedPaneWin with
// NativeTabbedPaneView is completed (http://crbug.com/138059), then the
// TestAddRemove method should be inlined here again and the "ifdef" part
// should be deleted.
#if defined(OS_WIN) && !defined(USE_AURA)
TestAddRemove(tabbed_pane_win_);
#endif
}
} // namespace
} // namespace views
......@@ -22,7 +22,6 @@ void TabbedPaneExample::CreateExampleView(View* container) {
tabbed_pane_->set_listener(this);
add_ = new TextButton(this, ASCIIToUTF16("Add"));
add_at_ = new TextButton(this, ASCIIToUTF16("Add At 1"));
remove_at_ = new TextButton(this, ASCIIToUTF16("Remove At 1"));
select_at_ = new TextButton(this, ASCIIToUTF16("Select At 1"));
GridLayout* layout = new GridLayout(container);
......@@ -42,7 +41,7 @@ void TabbedPaneExample::CreateExampleView(View* container) {
// Add control buttons horizontally.
const int button_column = 1;
column_set = layout->AddColumnSet(button_column);
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 3; i++) {
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
1.0f, GridLayout::USE_PREF, 0, 0);
}
......@@ -50,7 +49,6 @@ void TabbedPaneExample::CreateExampleView(View* container) {
layout->StartRow(0 /* no expand */, button_column);
layout->AddView(add_);
layout->AddView(add_at_);
layout->AddView(remove_at_);
layout->AddView(select_at_);
}
......@@ -59,10 +57,7 @@ void TabbedPaneExample::ButtonPressed(Button* sender, const ui::Event& event) {
AddButton("Added");
} else if (sender == add_at_) {
const string16 label = ASCIIToUTF16("Added at 1");
tabbed_pane_->AddTabAtIndex(1, label, new TextButton(NULL, label), true);
} else if (sender == remove_at_) {
if (tabbed_pane_->GetTabCount() > 1)
delete tabbed_pane_->RemoveTabAtIndex(1);
tabbed_pane_->AddTabAtIndex(1, label, new TextButton(NULL, label));
} else if (sender == select_at_) {
if (tabbed_pane_->GetTabCount() > 1)
tabbed_pane_->SelectTabAt(1);
......@@ -78,7 +73,7 @@ void TabbedPaneExample::TabSelectedAt(int index) {
void TabbedPaneExample::PrintStatus() {
ExampleBase::PrintStatus("Tab Count:%d, Selected Tab:%d",
tabbed_pane_->GetTabCount(),
tabbed_pane_->GetSelectedTabIndex());
tabbed_pane_->selected_tab_index());
}
void TabbedPaneExample::AddButton(const std::string& label) {
......
......@@ -18,7 +18,7 @@ class TabbedPane;
namespace examples {
// A TabbedPane example tests adding/removing/selecting tabs.
// A TabbedPane example tests adding and selecting tabs.
class TabbedPaneExample : public ExampleBase,
public ButtonListener,
public TabbedPaneListener {
......@@ -44,10 +44,9 @@ class TabbedPaneExample : public ExampleBase,
// The tabbed pane to be tested.
TabbedPane* tabbed_pane_;
// Control buttons to add, remove or select tabs.
// Control buttons to add and select tabs.
Button* add_;
Button* add_at_;
Button* remove_at_;
Button* select_at_;
DISALLOW_COPY_AND_ASSIGN(TabbedPaneExample);
......
......@@ -19,9 +19,6 @@
#if defined(USE_AURA)
#include "ui/aura/client/focus_client.h"
#include "ui/aura/window.h"
#else
#include "ui/views/controls/tabbed_pane/native_tabbed_pane_wrapper.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#endif
namespace views {
......@@ -175,63 +172,14 @@ class TestTextfield : public Textfield {
}
};
class TestTabbedPane : public TabbedPane {
public:
TestTabbedPane() {}
virtual gfx::NativeView TestGetNativeControlView() {
return native_tabbed_pane_->GetTestingHandle();
}
};
// Tests that NativeControls do set the focused View appropriately on the
// FocusManager.
TEST_F(FocusManagerTest, DISABLED_FocusNativeControls) {
TestTextfield* textfield = new TestTextfield();
TestTabbedPane* tabbed_pane = new TestTabbedPane();
tabbed_pane->set_use_native_win_control(true);
TestTextfield* textfield2 = new TestTextfield();
GetContentsView()->AddChildView(textfield);
GetContentsView()->AddChildView(tabbed_pane);
tabbed_pane->AddTab(ASCIIToUTF16("Awesome textfield"), textfield2);
// Simulate the native view getting the native focus (such as by user click).
FocusNativeView(textfield->TestGetNativeControlView());
EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView());
FocusNativeView(tabbed_pane->TestGetNativeControlView());
EXPECT_EQ(tabbed_pane, GetFocusManager()->GetFocusedView());
FocusNativeView(textfield2->TestGetNativeControlView());
EXPECT_EQ(textfield2, GetFocusManager()->GetFocusedView());
}
#endif
// There is no tabbed pane in Aura.
#if !defined(USE_AURA)
TEST_F(FocusManagerTest, ContainsView) {
View* view = new View();
scoped_ptr<View> detached_view(new View());
TabbedPane* tabbed_pane = new TabbedPane();
tabbed_pane->set_use_native_win_control(true);
TabbedPane* nested_tabbed_pane = new TabbedPane();
nested_tabbed_pane->set_use_native_win_control(true);
NativeTextButton* tab_button = new NativeTextButton(
NULL, ASCIIToUTF16("tab button"));
GetContentsView()->AddChildView(view);
GetContentsView()->AddChildView(tabbed_pane);
// Adding a View inside a TabbedPane to test the case of nested root view.
tabbed_pane->AddTab(ASCIIToUTF16("Awesome tab"), nested_tabbed_pane);
nested_tabbed_pane->AddTab(ASCIIToUTF16("Awesomer tab"), tab_button);
EXPECT_TRUE(GetFocusManager()->ContainsView(view));
EXPECT_TRUE(GetFocusManager()->ContainsView(tabbed_pane));
EXPECT_TRUE(GetFocusManager()->ContainsView(nested_tabbed_pane));
EXPECT_TRUE(GetFocusManager()->ContainsView(tab_button));
EXPECT_FALSE(GetFocusManager()->ContainsView(detached_view.get()));
}
#endif
......@@ -639,13 +587,9 @@ class FocusManagerDtorTest : public FocusManagerTest {
#if !defined(USE_AURA)
TEST_F(FocusManagerDtorTest, FocusManagerDestructedLast) {
// Setup views hierarchy.
TabbedPane* tabbed_pane = new TabbedPane();
tabbed_pane->set_use_native_win_control(true);
GetContentsView()->AddChildView(tabbed_pane);
NativeButtonDtorTracked* button = new NativeButtonDtorTracked(
ASCIIToUTF16("button"), &dtor_tracker_);
tabbed_pane->AddTab(ASCIIToUTF16("Awesome tab"), button);
GetContentsView()->AddChildView(new TestTextfield());
GetContentsView()->AddChildView(new NativeButtonDtorTracked(
ASCIIToUTF16("button"), &dtor_tracker_));
// Close the window.
GetWidget()->Close();
......
......@@ -15,15 +15,12 @@
#include "ui/views/controls/link.h"
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/focus/focus_manager_test.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
#if !defined(USE_AURA)
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#endif
namespace views {
namespace {
......@@ -68,14 +65,12 @@ const int kOKButtonID = count++;
const int kCancelButtonID = count++;
const int kHelpButtonID = count++;
#if !defined(USE_AURA)
const int kStyleContainerID = count++; // 35
const int kBoldCheckBoxID = count++;
const int kItalicCheckBoxID = count++;
const int kUnderlinedCheckBoxID = count++;
const int kStyleHelpLinkID = count++;
const int kStyleTextEditID = count++; // 40
#endif
const int kSearchContainerID = count++;
const int kSearchTextfieldID = count++;
......@@ -199,10 +194,8 @@ class FocusTraversalTest : public FocusManagerTest {
View* view = GetContentsView()->GetViewByID(id);
if (view)
return view;
#if !defined(USE_AURA)
if (style_tab_)
view = style_tab_->GetSelectedTab()->GetViewByID(id);
#endif
if (view)
return view;
view = search_border_view_->GetContentsRootView()->GetViewByID(id);
......@@ -212,9 +205,7 @@ class FocusTraversalTest : public FocusManagerTest {
}
protected:
#if !defined(USE_AURA)
TabbedPane* style_tab_;
#endif
BorderView* search_border_view_;
DummyComboboxModel combobox_model_;
PaneView* left_container_;
......@@ -224,10 +215,7 @@ class FocusTraversalTest : public FocusManagerTest {
};
FocusTraversalTest::FocusTraversalTest()
:
#if !defined(USE_AURA)
style_tab_(NULL),
#endif
: style_tab_(NULL),
search_border_view_(NULL) {
}
......@@ -276,7 +264,6 @@ void FocusTraversalTest::InitContentView() {
// NativeButton * kOKButtonID
// NativeButton * kCancelButtonID
// NativeButton * kHelpButtonID
// #if !defined(USE_AURA)
// TabbedPane * kStyleContainerID
// View
// Checkbox * kBoldCheckBoxID
......@@ -285,7 +272,6 @@ void FocusTraversalTest::InitContentView() {
// Link * kStyleHelpLinkID
// Textfield * kStyleTextEditID
// Other
// #endif
// BorderView kSearchContainerID
// View
// Textfield * kSearchTextfieldID
......@@ -489,7 +475,6 @@ void FocusTraversalTest::InitContentView() {
View* contents = NULL;
Link* link = NULL;
#if !defined(USE_AURA)
// Left bottom box with style checkboxes.
contents = new View();
contents->set_background(Background::CreateSolidBackground(SK_ColorWHITE));
......@@ -524,7 +509,6 @@ void FocusTraversalTest::InitContentView() {
style_tab_->SetBounds(10, y, 210, 100);
style_tab_->AddTab(ASCIIToUTF16("Style"), contents);
style_tab_->AddTab(ASCIIToUTF16("Other"), new View());
#endif
// Right bottom box with search.
contents = new View();
......@@ -581,10 +565,8 @@ TEST_F(FocusTraversalTest, NormalTraversal) {
kDinerGameLinkID, kRidiculeLinkID, kClosetLinkID, kVisitingLinkID,
kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID,
kTaxiLinkID, kAsterixLinkID, kOKButtonID, kCancelButtonID, kHelpButtonID,
#if !defined(USE_AURA)
kStyleContainerID, kBoldCheckBoxID, kItalicCheckBoxID,
kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID,
#endif
kSearchTextfieldID, kSearchButtonID, kHelpLinkID,
kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID };
......@@ -622,21 +604,15 @@ TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) {
const int kDisabledIDs[] = {
kBananaTextfieldID, kFruitCheckBoxID, kComboboxID, kAsparagusButtonID,
kCauliflowerButtonID, kClosetLinkID, kVisitingLinkID, kBriceDeNiceLinkID,
kTaxiLinkID, kAsterixLinkID, kHelpButtonID,
#if !defined(USE_AURA)
kBoldCheckBoxID,
#endif
kTaxiLinkID, kAsterixLinkID, kHelpButtonID, kBoldCheckBoxID,
kSearchTextfieldID, kHelpLinkID };
const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextfieldID,
kOrangeTextfieldID, kKiwiTextfieldID, kFruitButtonID, kBroccoliButtonID,
kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID,
kRidiculeLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID,
kOKButtonID, kCancelButtonID,
#if !defined(USE_AURA)
kStyleContainerID, kItalicCheckBoxID, kUnderlinedCheckBoxID,
kStyleHelpLinkID, kStyleTextEditID,
#endif
kOKButtonID, kCancelButtonID, kStyleContainerID, kItalicCheckBoxID,
kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID,
kSearchButtonID, kThumbnailContainerID, kThumbnailStarID,
kThumbnailSuperStarID };
......@@ -687,12 +663,9 @@ TEST_F(FocusTraversalTest, TraversalWithInvisibleViews) {
kStupeurEtTremblementLinkID, kDinerGameLinkID, kRidiculeLinkID,
kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID,
kCampingLinkID, kBriceDeNiceLinkID, kTaxiLinkID, kAsterixLinkID,
kCancelButtonID, kHelpButtonID,
#if !defined(USE_AURA)
kStyleContainerID, kBoldCheckBoxID, kItalicCheckBoxID,
kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID,
#endif
kSearchTextfieldID, kSearchButtonID, kHelpLinkID };
kCancelButtonID, kHelpButtonID, kStyleContainerID, kBoldCheckBoxID,
kItalicCheckBoxID, kUnderlinedCheckBoxID, kStyleHelpLinkID,
kStyleTextEditID, kSearchTextfieldID, kSearchButtonID, kHelpLinkID };
// Let's make some views invisible.
......
......@@ -195,11 +195,6 @@
'controls/slide_out_view.h',
'controls/slider.cc',
'controls/slider.h',
'controls/tabbed_pane/native_tabbed_pane_views.cc',
'controls/tabbed_pane/native_tabbed_pane_views.h',
'controls/tabbed_pane/native_tabbed_pane_win.cc',
'controls/tabbed_pane/native_tabbed_pane_win.h',
'controls/tabbed_pane/native_tabbed_pane_wrapper.h',
'controls/tabbed_pane/tabbed_pane.cc',
'controls/tabbed_pane/tabbed_pane.h',
'controls/tabbed_pane/tabbed_pane_listener.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment