Skip to content

Commit

Permalink
Removes unnecessary views::Widget::InitParams::top_level
Browse files Browse the repository at this point in the history
BUG=353533
TEST=None
R=sky
TBR=benwells (For trivial change to apps/ui/views/native_app_window_views.cc)

Review URL: https://codereview.chromium.org/282133005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272287 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
pkotwicz@chromium.org committed May 22, 2014
1 parent 3c69bfd commit f7e5d90
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 83 deletions.
1 change: 0 additions & 1 deletion apps/ui/views/native_app_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void NativeAppWindowViews::InitializeWindow(
// Stub implementation. See also ChromeNativeAppWindowViews.
views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW);
init_params.delegate = this;
init_params.top_level = true;
init_params.keep_on_top = create_params.always_on_top;
widget_->Init(init_params);
widget_->CenterWindow(
Expand Down
2 changes: 1 addition & 1 deletion ash/shell/content_client/shell_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ShellViewsDelegate : public views::TestViewsDelegate {
if (params->native_widget)
return;

if (!params->parent && !params->context && params->top_level)
if (!params->parent && !params->context && !params->child)
params->context = Shell::GetPrimaryRootWindow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ void ChromeNativeAppWindowViews::InitializeDefaultWindow(
init_params.delegate = this;
init_params.remove_standard_frame = IsFrameless() || has_frame_color_;
init_params.use_system_default_icon = true;
// TODO(erg): Conceptually, these are toplevel windows, but we theoretically
// could plumb context through to here in some cases.
init_params.top_level = true;
if (create_params.transparent_background)
init_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
init_params.keep_on_top = create_params.always_on_top;
Expand Down Expand Up @@ -317,9 +314,6 @@ void ChromeNativeAppWindowViews::InitializePanelWindow(
#else
params.bounds = gfx::Rect(preferred_size_);
#endif
// TODO(erg): Conceptually, these are toplevel windows, but we theoretically
// could plumb context through to here in some cases.
params.top_level = true;
widget()->Init(params);
widget()->set_focus_on_creation(create_params.focused);

Expand Down
24 changes: 13 additions & 11 deletions chrome/browser/ui/views/chrome_views_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,14 @@ void ChromeViewsDelegate::OnBeforeWidgetInit(
// On desktop Linux Chrome must run in an environment that supports a variety
// of window managers, some of which do not play nicely with parts of our UI
// that have specific expectations about window sizing and placement. For this
// reason windows opened as top level (params.top_level) are always
// constrained by the browser frame, so we can position them correctly. This
// has some negative side effects, like dialogs being clipped by the browser
// frame, but the side effects are not as bad as the poor window manager
// interactions. On Windows however these WM interactions are not an issue, so
// we open windows requested as top_level as actual top level windows on the
// desktop.
// reason windows opened as top level (!params.child) are always constrained
// by the browser frame, so we can position them correctly. This has some
// negative side effects, like dialogs being clipped by the browser frame, but
// the side effects are not as bad as the poor window manager interactions. On
// Windows however these WM interactions are not an issue, so we open windows
// requested as top_level as actual top level windows on the desktop.
use_non_toplevel_window = use_non_toplevel_window &&
(!params->top_level ||
(params->child ||
chrome::GetHostDesktopTypeForNativeView(params->parent) !=
chrome::HOST_DESKTOP_TYPE_NATIVE);

Expand Down Expand Up @@ -314,15 +313,18 @@ void ChromeViewsDelegate::OnBeforeWidgetInit(
// context.
if (params->context)
params->context = params->context->GetRootWindow();
DCHECK(params->parent || params->context || params->top_level)
DCHECK(params->parent || params->context || !params->child)
<< "Please provide a parent or context for this widget.";
if (!params->parent && !params->context)
params->context = ash::Shell::GetPrimaryRootWindow();
#elif defined(USE_AURA)
// While the majority of the time, context wasn't plumbed through due to the
// existence of a global WindowTreeClient, if this window is a toplevel, it's
// existence of a global WindowTreeClient, if this window is toplevel, it's
// possible that there is no contextual state that we can use.
if (params->parent == NULL && params->context == NULL && params->top_level) {
if (params->parent == NULL &&
params->context == NULL &&
!params->child &&
params->type != views::Widget::InitParams::TYPE_TOOLTIP) {
// We need to make a decision about where to place this window based on the
// desktop type.
switch (chrome::GetActiveDesktop()) {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/chrome_views_delegate_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ChromeViewsDelegate::GetOpacityForInitParams(
#endif
// We want translucent windows when either we are in ASH or we are
// a top level window which is not of type TYPE_WINDOW.
if (params.top_level && params.type != views::Widget::InitParams::TYPE_WINDOW)
if (!params.child && params.type != views::Widget::InitParams::TYPE_WINDOW)
return views::Widget::InitParams::TRANSLUCENT_WINDOW;

return views::Widget::InitParams::OPAQUE_WINDOW;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ void MessageCenterWidgetDelegate::InitWidget() {
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.delegate = this;
params.keep_on_top = true;
params.top_level = true;
#if defined(USE_ASH)
// This class is not used in Ash; there is another container for the message
// center that's used there. So, we must be in a Views + Ash environment. We
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ gfx::NativeViewId ScreenCaptureNotificationUIViews::OnStarted(
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.remove_standard_frame = true;
params.keep_on_top = true;
params.top_level = true;

#if defined(USE_ASH)
// TODO(sergeyu): The notification bar must be shown on the monitor that's
Expand Down
1 change: 0 additions & 1 deletion content/shell/browser/shell_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ void Shell::PlatformCreateWindow(int width, int height) {
views::Widget::InitParams params;
params.bounds = gfx::Rect(0, 0, width, height);
params.delegate = new ShellWindowDelegateView(this);
params.top_level = true;
params.remove_standard_frame = true;
window_widget_->Init(params);
#endif
Expand Down
2 changes: 1 addition & 1 deletion ui/app_list/views/app_list_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void AppListViewTestDesktop::AppListViewTestViewsDelegate::OnBeforeWidgetInit(
if (!params->parent && !params->context)
params->context = parent_->GetContext();
#elif defined(USE_AURA)
if (params->parent == NULL && params->context == NULL && params->top_level)
if (params->parent == NULL && params->context == NULL && !params->child)
params->native_widget = new views::DesktopNativeWidgetAura(delegate);
#endif
}
Expand Down
2 changes: 0 additions & 2 deletions ui/message_center/views/toast_contents_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ void ToastContentsView::CreateWidget(gfx::NativeView parent) {
params.keep_on_top = true;
if (parent)
params.parent = parent;
else
params.top_level = true;
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.delegate = this;
views::Widget* widget = new views::Widget();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ TEST_F(NativeViewAcccessibilityWinTest, AuraOwnedWidgets) {
Widget::InitParams owned_init_params =
CreateParams(Widget::InitParams::TYPE_POPUP);
owned_init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
owned_init_params.child = false;
owned_init_params.parent = widget.GetNativeView();
owned_widget.Init(owned_init_params);
owned_widget.Show();
Expand Down
1 change: 0 additions & 1 deletion ui/views/examples/examples_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ void ShowExamplesWindow(Operation operation,
params.delegate = new ExamplesWindowContents(operation, examples.Pass());
params.context = window_context;
params.bounds = gfx::Rect(0, 0, 850, 300);
params.top_level = true;
params.remove_standard_frame = true;
widget->Init(params);
widget->Show();
Expand Down
1 change: 0 additions & 1 deletion ui/views/widget/native_widget_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class NativeWidgetTest : public ViewsTestBase {
Widget* widget = new Widget;
Widget::InitParams params = CreateParams(type);
params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
params.child = false; // Implicitly set to true by ctor with TYPE_CONTROL.
params.bounds = gfx::Rect(10, 10, 200, 200);
widget->Init(params);
return widget->native_widget_private();
Expand Down
12 changes: 3 additions & 9 deletions ui/views/widget/widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ Widget::InitParams::InitParams()
parent(NULL),
native_widget(NULL),
desktop_window_tree_host(NULL),
top_level(false),
layer_type(aura::WINDOW_LAYER_TEXTURED),
context(NULL),
force_show_in_taskbar(false) {
Expand All @@ -127,7 +126,7 @@ Widget::InitParams::InitParams()
Widget::InitParams::InitParams(Type type)
: type(type),
delegate(NULL),
child(type == TYPE_CONTROL),
child(false),
opacity(INFER_OPACITY),
accept_events(true),
activatable(ACTIVATABLE_DEFAULT),
Expand All @@ -143,7 +142,6 @@ Widget::InitParams::InitParams(Type type)
parent(NULL),
native_widget(NULL),
desktop_window_tree_host(NULL),
top_level(false),
layer_type(aura::WINDOW_LAYER_TEXTURED),
context(NULL),
force_show_in_taskbar(false) {
Expand Down Expand Up @@ -202,7 +200,6 @@ Widget* Widget::CreateWindowWithBounds(WidgetDelegate* delegate,
Widget::InitParams params;
params.bounds = bounds;
params.delegate = delegate;
params.top_level = true;
widget->Init(params);
return widget;
}
Expand Down Expand Up @@ -332,11 +329,8 @@ void Widget::Init(const InitParams& in_params) {
TRACE_EVENT0("views", "Widget::Init");
InitParams params = in_params;

is_top_level_ = params.top_level ||
(!params.child &&
params.type != InitParams::TYPE_CONTROL &&
params.type != InitParams::TYPE_TOOLTIP);
params.top_level = is_top_level_;
params.child |= (params.type == InitParams::TYPE_CONTROL);
is_top_level_ = (!params.child && params.type != InitParams::TYPE_TOOLTIP);

if (params.opacity == views::Widget::InitParams::INFER_OPACITY &&
params.type != views::Widget::InitParams::TYPE_WINDOW &&
Expand Down
4 changes: 0 additions & 4 deletions ui/views/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// TODO(beng): Figure out if there's a better way to expose this, e.g. get
// rid of NW subclasses and do this all via message handling.
DesktopWindowTreeHost* desktop_window_tree_host;
// Whether this window is intended to be a toplevel window with no
// attachment to any other window. (This may be a transient window if
// |parent| is set.)
bool top_level;
// Only used by NativeWidgetAura. Specifies the type of layer for the
// aura::Window. Default is WINDOW_LAYER_TEXTURED.
aura::WindowLayerType layer_type;
Expand Down
40 changes: 0 additions & 40 deletions ui/views/widget/widget_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1683,46 +1683,6 @@ TEST_F(WidgetWindowTitleTest, SetWindowTitleChanged_DesktopNativeWidget) {
}
#endif // !OS_CHROMEOS

// Used by SetTopLevelCorrectly to track calls to OnBeforeWidgetInit().
class VerifyTopLevelDelegate : public TestViewsDelegate {
public:
VerifyTopLevelDelegate()
: on_before_init_called_(false),
is_top_level_(false) {
}

bool on_before_init_called() const { return on_before_init_called_; }
bool is_top_level() const { return is_top_level_; }

virtual void OnBeforeWidgetInit(
Widget::InitParams* params,
internal::NativeWidgetDelegate* delegate) OVERRIDE {
on_before_init_called_ = true;
is_top_level_ = params->top_level;
}

private:
bool on_before_init_called_;
bool is_top_level_;

DISALLOW_COPY_AND_ASSIGN(VerifyTopLevelDelegate);
};

// Verifies |top_level| is correctly passed to
// ViewsDelegate::OnBeforeWidgetInit().
TEST_F(WidgetTest, SetTopLevelCorrectly) {
set_views_delegate(NULL);
VerifyTopLevelDelegate* delegate = new VerifyTopLevelDelegate;
set_views_delegate(delegate); // ViewsTestBase takes ownership.
scoped_ptr<Widget> widget(new Widget);
Widget::InitParams params =
CreateParams(views::Widget::InitParams::TYPE_POPUP);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget->Init(params);
EXPECT_TRUE(delegate->on_before_init_called());
EXPECT_TRUE(delegate->is_top_level());
}

TEST_F(WidgetTest, WidgetDeleted_InOnMousePressed) {
Widget* widget = new Widget;
Widget::InitParams params =
Expand Down
1 change: 0 additions & 1 deletion ui/views/window/dialog_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Widget* DialogDelegate::CreateDialogWidget(DialogDelegate* dialog,
}
params.context = context;
params.parent = parent;
params.top_level = true;
// TODO(msw): Add a matching shadow type and remove the bubble frame border?
params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
widget->Init(params);
Expand Down

0 comments on commit f7e5d90

Please sign in to comment.