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

Side by Side Diff: views/widget/widget.h

Issue 7031053: Make Widget ownership a little clearer by expressing it in terms of an enum. (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/widget/native_widget_win_unittest.cc ('k') | views/widget/widget.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 #ifndef VIEWS_WIDGET_WIDGET_H_ 5 #ifndef VIEWS_WIDGET_WIDGET_H_
6 #define VIEWS_WIDGET_WIDGET_H_ 6 #define VIEWS_WIDGET_WIDGET_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // 49 //
50 // Encapsulates the platform-specific rendering, event receiving and widget 50 // Encapsulates the platform-specific rendering, event receiving and widget
51 // management aspects of the UI framework. 51 // management aspects of the UI framework.
52 // 52 //
53 // Owns a RootView and thus a View hierarchy. Can contain child Widgets. 53 // Owns a RootView and thus a View hierarchy. Can contain child Widgets.
54 // Widget is a platform-independent type that communicates with a platform or 54 // Widget is a platform-independent type that communicates with a platform or
55 // context specific NativeWidget implementation. 55 // context specific NativeWidget implementation.
56 // 56 //
57 // A special note on ownership: 57 // A special note on ownership:
58 // 58 //
59 // Depending on the value of "delete_on_destroy", the Widget either owns or 59 // Depending on the value of the InitParams' ownership field, the Widget
60 // is owned by its NativeWidget: 60 // either owns or is owned by its NativeWidget:
61 // 61 //
62 // delete_on_destroy = true (default) 62 // ownership = NATIVE_WIDGET_OWNS_WIDGET (default)
63 // The Widget instance is owned by its NativeWidget. When the NativeWidget 63 // The Widget instance is owned by its NativeWidget. When the NativeWidget
64 // is destroyed (in response to a native destruction message), it deletes 64 // is destroyed (in response to a native destruction message), it deletes
65 // the Widget from its destructor. 65 // the Widget from its destructor.
66 // delete_on_destroy = false (non-default) 66 // ownership = WIDGET_OWNS_NATIVE_WIDGET (non-default)
67 // The Widget instance owns its NativeWidget. This state implies someone 67 // The Widget instance owns its NativeWidget. This state implies someone
68 // else wants to control the lifetime of this object. When they destroy 68 // else wants to control the lifetime of this object. When they destroy
69 // the Widget it is responsible for destroying the NativeWidget (from its 69 // the Widget it is responsible for destroying the NativeWidget (from its
70 // destructor). 70 // destructor).
71 // 71 //
72 class Widget : public internal::NativeWidgetDelegate, 72 class Widget : public internal::NativeWidgetDelegate,
73 public FocusTraversable { 73 public FocusTraversable {
74 public: 74 public:
75 struct InitParams { 75 struct InitParams {
76 enum Type { 76 enum Type {
77 TYPE_WINDOW, // A Window, like a frame window. 77 TYPE_WINDOW, // A Window, like a frame window.
78 TYPE_CONTROL, // A control, like a button. 78 TYPE_CONTROL, // A control, like a button.
79 TYPE_POPUP, // An undecorated Window, with transient properties. 79 TYPE_POPUP, // An undecorated Window, with transient properties.
80 TYPE_MENU // An undecorated Window, with transient properties 80 TYPE_MENU // An undecorated Window, with transient properties
81 // specialized to menus. 81 // specialized to menus.
82 }; 82 };
83 enum Ownership {
84 // Default. Creator is not responsible for managing the lifetime of the
85 // Widget, it is destroyed when the corresponding NativeWidget is
86 // destroyed.
87 NATIVE_WIDGET_OWNS_WIDGET,
88 // Used when the Widget is owned by someone other than the NativeWidget,
89 // e.g. a scoped_ptr in tests.
90 WIDGET_OWNS_NATIVE_WIDGET
91 };
83 92
84 InitParams(); 93 InitParams();
85 explicit InitParams(Type type); 94 explicit InitParams(Type type);
86 95
87 Type type; 96 Type type;
88 bool child; 97 bool child;
89 bool transient; 98 bool transient;
90 bool transparent; 99 bool transparent;
91 bool accept_events; 100 bool accept_events;
92 bool can_activate; 101 bool can_activate;
93 bool keep_on_top; 102 bool keep_on_top;
94 bool delete_on_destroy; 103 Ownership ownership;
95 bool mirror_origin_in_rtl; 104 bool mirror_origin_in_rtl;
96 bool has_dropshadow; 105 bool has_dropshadow;
97 // Should the widget be double buffered? Default is false. 106 // Should the widget be double buffered? Default is false.
98 bool double_buffer; 107 bool double_buffer;
99 gfx::NativeView parent; 108 gfx::NativeView parent;
100 Widget* parent_widget; 109 Widget* parent_widget;
101 gfx::Rect bounds; 110 gfx::Rect bounds;
102 NativeWidget* native_widget; 111 NativeWidget* native_widget;
103 }; 112 };
104 static InitParams WindowInitParams(); 113 static InitParams WindowInitParams();
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 scoped_ptr<DefaultThemeProvider> default_theme_provider_; 402 scoped_ptr<DefaultThemeProvider> default_theme_provider_;
394 403
395 // Valid for the lifetime of RunShellDrag(), indicates the view the drag 404 // Valid for the lifetime of RunShellDrag(), indicates the view the drag
396 // started from. 405 // started from.
397 View* dragged_view_; 406 View* dragged_view_;
398 407
399 // The compositor for accelerated drawing. 408 // The compositor for accelerated drawing.
400 scoped_refptr<ui::Compositor> compositor_; 409 scoped_refptr<ui::Compositor> compositor_;
401 410
402 // See class documentation for Widget above for a note about ownership. 411 // See class documentation for Widget above for a note about ownership.
403 bool delete_on_destroy_; 412 InitParams::Ownership ownership_;
404 413
405 // See set_is_secondary_widget(). 414 // See set_is_secondary_widget().
406 bool is_secondary_widget_; 415 bool is_secondary_widget_;
407 416
408 DISALLOW_COPY_AND_ASSIGN(Widget); 417 DISALLOW_COPY_AND_ASSIGN(Widget);
409 }; 418 };
410 419
411 } // namespace views 420 } // namespace views
412 421
413 #endif // VIEWS_WIDGET_WIDGET_H_ 422 #endif // VIEWS_WIDGET_WIDGET_H_
OLDNEW
« no previous file with comments | « views/widget/native_widget_win_unittest.cc ('k') | views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698