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

Side by Side Diff: ui/views/widget/widget.cc

Issue 297503003: Revert: [Refactor] Consolidate the logic for whether a widget can be activated. This is a first ste (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | « ui/views/widget/widget.h ('k') | ui/views/widget/widget_hwnd_utils.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/widget/widget.h" 5 #include "ui/views/widget/widget.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 return native_widget; 63 return native_widget;
64 } 64 }
65 65
66 } // namespace 66 } // namespace
67 67
68 // A default implementation of WidgetDelegate, used by Widget when no 68 // A default implementation of WidgetDelegate, used by Widget when no
69 // WidgetDelegate is supplied. 69 // WidgetDelegate is supplied.
70 class DefaultWidgetDelegate : public WidgetDelegate { 70 class DefaultWidgetDelegate : public WidgetDelegate {
71 public: 71 public:
72 DefaultWidgetDelegate(Widget* widget, bool can_activate) 72 DefaultWidgetDelegate(Widget* widget, const Widget::InitParams& params)
73 : widget_(widget), 73 : widget_(widget),
74 can_activate_(can_activate) { 74 can_activate_(!params.child &&
75 params.type != Widget::InitParams::TYPE_POPUP &&
76 params.type != Widget::InitParams::TYPE_DRAG) {
75 } 77 }
76 virtual ~DefaultWidgetDelegate() {} 78 virtual ~DefaultWidgetDelegate() {}
77 79
78 // Overridden from WidgetDelegate: 80 // Overridden from WidgetDelegate:
79 virtual void DeleteDelegate() OVERRIDE { 81 virtual void DeleteDelegate() OVERRIDE {
80 delete this; 82 delete this;
81 } 83 }
82 virtual Widget* GetWidget() OVERRIDE { 84 virtual Widget* GetWidget() OVERRIDE {
83 return widget_; 85 return widget_;
84 } 86 }
(...skipping 19 matching lines...) Expand all
104 106
105 //////////////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////////////////
106 // Widget, InitParams: 108 // Widget, InitParams:
107 109
108 Widget::InitParams::InitParams() 110 Widget::InitParams::InitParams()
109 : type(TYPE_WINDOW), 111 : type(TYPE_WINDOW),
110 delegate(NULL), 112 delegate(NULL),
111 child(false), 113 child(false),
112 opacity(INFER_OPACITY), 114 opacity(INFER_OPACITY),
113 accept_events(true), 115 accept_events(true),
114 activatable(ACTIVATABLE_DEFAULT), 116 can_activate(true),
115 keep_on_top(false), 117 keep_on_top(false),
116 visible_on_all_workspaces(false), 118 visible_on_all_workspaces(false),
117 ownership(NATIVE_WIDGET_OWNS_WIDGET), 119 ownership(NATIVE_WIDGET_OWNS_WIDGET),
118 mirror_origin_in_rtl(false), 120 mirror_origin_in_rtl(false),
119 has_dropshadow(false), 121 has_dropshadow(false),
120 remove_standard_frame(false), 122 remove_standard_frame(false),
121 use_system_default_icon(false), 123 use_system_default_icon(false),
122 show_state(ui::SHOW_STATE_DEFAULT), 124 show_state(ui::SHOW_STATE_DEFAULT),
123 double_buffer(false), 125 double_buffer(false),
124 parent(NULL), 126 parent(NULL),
125 native_widget(NULL), 127 native_widget(NULL),
126 desktop_window_tree_host(NULL), 128 desktop_window_tree_host(NULL),
127 top_level(false), 129 top_level(false),
128 layer_type(aura::WINDOW_LAYER_TEXTURED), 130 layer_type(aura::WINDOW_LAYER_TEXTURED),
129 context(NULL), 131 context(NULL),
130 force_show_in_taskbar(false) { 132 force_show_in_taskbar(false) {
131 } 133 }
132 134
133 Widget::InitParams::InitParams(Type type) 135 Widget::InitParams::InitParams(Type type)
134 : type(type), 136 : type(type),
135 delegate(NULL), 137 delegate(NULL),
136 child(type == TYPE_CONTROL), 138 child(type == TYPE_CONTROL),
137 opacity(INFER_OPACITY), 139 opacity(INFER_OPACITY),
138 accept_events(true), 140 accept_events(true),
139 activatable(ACTIVATABLE_DEFAULT), 141 can_activate(type != TYPE_POPUP && type != TYPE_MENU &&
142 type != TYPE_DRAG),
140 keep_on_top(type == TYPE_MENU || type == TYPE_DRAG), 143 keep_on_top(type == TYPE_MENU || type == TYPE_DRAG),
141 visible_on_all_workspaces(false), 144 visible_on_all_workspaces(false),
142 ownership(NATIVE_WIDGET_OWNS_WIDGET), 145 ownership(NATIVE_WIDGET_OWNS_WIDGET),
143 mirror_origin_in_rtl(false), 146 mirror_origin_in_rtl(false),
144 has_dropshadow(false), 147 has_dropshadow(false),
145 remove_standard_frame(false), 148 remove_standard_frame(false),
146 use_system_default_icon(false), 149 use_system_default_icon(false),
147 show_state(ui::SHOW_STATE_DEFAULT), 150 show_state(ui::SHOW_STATE_DEFAULT),
148 double_buffer(false), 151 double_buffer(false),
149 parent(NULL), 152 parent(NULL),
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 void Widget::Init(const InitParams& in_params) { 340 void Widget::Init(const InitParams& in_params) {
338 TRACE_EVENT0("views", "Widget::Init"); 341 TRACE_EVENT0("views", "Widget::Init");
339 InitParams params = in_params; 342 InitParams params = in_params;
340 343
341 is_top_level_ = params.top_level || 344 is_top_level_ = params.top_level ||
342 (!params.child && 345 (!params.child &&
343 params.type != InitParams::TYPE_CONTROL && 346 params.type != InitParams::TYPE_CONTROL &&
344 params.type != InitParams::TYPE_TOOLTIP); 347 params.type != InitParams::TYPE_TOOLTIP);
345 params.top_level = is_top_level_; 348 params.top_level = is_top_level_;
346 349
347 if (params.activatable != InitParams::ACTIVATABLE_DEFAULT) {
348 can_activate_ = (params.activatable == InitParams::ACTIVATABLE_YES);
349 } else if (params.type != InitParams::TYPE_CONTROL &&
350 params.type != InitParams::TYPE_POPUP &&
351 params.type != InitParams::TYPE_MENU &&
352 params.type != InitParams::TYPE_TOOLTIP &&
353 params.type != InitParams::TYPE_DRAG) {
354 can_activate_ = true;
355 params.activatable = InitParams::ACTIVATABLE_YES;
356 } else {
357 can_activate_ = false;
358 params.activatable = InitParams::ACTIVATABLE_NO;
359 }
360
361 if (params.opacity == views::Widget::InitParams::INFER_OPACITY && 350 if (params.opacity == views::Widget::InitParams::INFER_OPACITY &&
362 params.type != views::Widget::InitParams::TYPE_WINDOW && 351 params.type != views::Widget::InitParams::TYPE_WINDOW &&
363 params.type != views::Widget::InitParams::TYPE_PANEL) 352 params.type != views::Widget::InitParams::TYPE_PANEL)
364 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; 353 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
365 354
366 if (ViewsDelegate::views_delegate) 355 if (ViewsDelegate::views_delegate)
367 ViewsDelegate::views_delegate->OnBeforeWidgetInit(&params, this); 356 ViewsDelegate::views_delegate->OnBeforeWidgetInit(&params, this);
368 357
369 if (params.opacity == views::Widget::InitParams::INFER_OPACITY) 358 if (params.opacity == views::Widget::InitParams::INFER_OPACITY)
370 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; 359 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
371 360
372 widget_delegate_ = params.delegate ? 361 widget_delegate_ = params.delegate ?
373 params.delegate : new DefaultWidgetDelegate(this, can_activate_); 362 params.delegate : new DefaultWidgetDelegate(this, params);
374 ownership_ = params.ownership; 363 ownership_ = params.ownership;
375 native_widget_ = CreateNativeWidget(params.native_widget, this)-> 364 native_widget_ = CreateNativeWidget(params.native_widget, this)->
376 AsNativeWidgetPrivate(); 365 AsNativeWidgetPrivate();
377 root_view_.reset(CreateRootView()); 366 root_view_.reset(CreateRootView());
378 default_theme_provider_.reset(new ui::DefaultThemeProvider); 367 default_theme_provider_.reset(new ui::DefaultThemeProvider);
379 if (params.type == InitParams::TYPE_MENU) { 368 if (params.type == InitParams::TYPE_MENU) {
380 is_mouse_button_pressed_ = 369 is_mouse_button_pressed_ =
381 internal::NativeWidgetPrivate::IsMouseButtonDown(); 370 internal::NativeWidgetPrivate::IsMouseButtonDown();
382 } 371 }
383 native_widget_->InitNativeWidget(params); 372 native_widget_->InitNativeWidget(params);
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 1001
1013 bool Widget::IsModal() const { 1002 bool Widget::IsModal() const {
1014 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE; 1003 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE;
1015 } 1004 }
1016 1005
1017 bool Widget::IsDialogBox() const { 1006 bool Widget::IsDialogBox() const {
1018 return !!widget_delegate_->AsDialogDelegate(); 1007 return !!widget_delegate_->AsDialogDelegate();
1019 } 1008 }
1020 1009
1021 bool Widget::CanActivate() const { 1010 bool Widget::CanActivate() const {
1022 return can_activate_ && widget_delegate_->CanActivate(); 1011 return widget_delegate_->CanActivate();
1023 } 1012 }
1024 1013
1025 bool Widget::IsInactiveRenderingDisabled() const { 1014 bool Widget::IsInactiveRenderingDisabled() const {
1026 return disable_inactive_rendering_; 1015 return disable_inactive_rendering_;
1027 } 1016 }
1028 1017
1029 void Widget::EnableInactiveRendering() { 1018 void Widget::EnableInactiveRendering() {
1030 SetInactiveRenderingDisabled(false); 1019 SetInactiveRenderingDisabled(false);
1031 } 1020 }
1032 1021
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 1503
1515 //////////////////////////////////////////////////////////////////////////////// 1504 ////////////////////////////////////////////////////////////////////////////////
1516 // internal::NativeWidgetPrivate, NativeWidget implementation: 1505 // internal::NativeWidgetPrivate, NativeWidget implementation:
1517 1506
1518 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1507 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1519 return this; 1508 return this;
1520 } 1509 }
1521 1510
1522 } // namespace internal 1511 } // namespace internal
1523 } // namespace views 1512 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget.h ('k') | ui/views/widget/widget_hwnd_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698