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

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

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/widget.h ('k') | no next file » | 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 "views/widget/widget.h" 5 #include "views/widget/widget.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "ui/gfx/compositor/compositor.h" 9 #include "ui/gfx/compositor/compositor.h"
10 #include "views/focus/view_storage.h" 10 #include "views/focus/view_storage.h"
(...skipping 15 matching lines...) Expand all
26 // Widget, InitParams: 26 // Widget, InitParams:
27 27
28 Widget::InitParams::InitParams() 28 Widget::InitParams::InitParams()
29 : type(TYPE_WINDOW), 29 : type(TYPE_WINDOW),
30 child(false), 30 child(false),
31 transient(false), 31 transient(false),
32 transparent(false), 32 transparent(false),
33 accept_events(true), 33 accept_events(true),
34 can_activate(true), 34 can_activate(true),
35 keep_on_top(false), 35 keep_on_top(false),
36 delete_on_destroy(true), 36 ownership(NATIVE_WIDGET_OWNS_WIDGET),
37 mirror_origin_in_rtl(false), 37 mirror_origin_in_rtl(false),
38 has_dropshadow(false), 38 has_dropshadow(false),
39 double_buffer(false), 39 double_buffer(false),
40 parent(NULL), 40 parent(NULL),
41 parent_widget(NULL), 41 parent_widget(NULL),
42 native_widget(NULL) { 42 native_widget(NULL) {
43 } 43 }
44 44
45 Widget::InitParams::InitParams(Type type) 45 Widget::InitParams::InitParams(Type type)
46 : type(type), 46 : type(type),
47 child(type == TYPE_CONTROL), 47 child(type == TYPE_CONTROL),
48 transient(type == TYPE_POPUP || type == TYPE_MENU), 48 transient(type == TYPE_POPUP || type == TYPE_MENU),
49 transparent(false), 49 transparent(false),
50 accept_events(true), 50 accept_events(true),
51 can_activate(type != TYPE_POPUP && type != TYPE_MENU), 51 can_activate(type != TYPE_POPUP && type != TYPE_MENU),
52 keep_on_top(type == TYPE_MENU), 52 keep_on_top(type == TYPE_MENU),
53 delete_on_destroy(true), 53 ownership(NATIVE_WIDGET_OWNS_WIDGET),
54 mirror_origin_in_rtl(false), 54 mirror_origin_in_rtl(false),
55 has_dropshadow(false), 55 has_dropshadow(false),
56 double_buffer(false), 56 double_buffer(false),
57 parent(NULL), 57 parent(NULL),
58 parent_widget(NULL), 58 parent_widget(NULL),
59 native_widget(NULL) { 59 native_widget(NULL) {
60 } 60 }
61 61
62 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
63 // Widget, public: 63 // Widget, public:
64 64
65 // static 65 // static
66 Widget::InitParams Widget::WindowInitParams() { 66 Widget::InitParams Widget::WindowInitParams() {
67 return InitParams(InitParams::TYPE_WINDOW); 67 return InitParams(InitParams::TYPE_WINDOW);
68 } 68 }
69 69
70 Widget::Widget() 70 Widget::Widget()
71 : is_mouse_button_pressed_(false), 71 : is_mouse_button_pressed_(false),
72 last_mouse_event_was_move_(false), 72 last_mouse_event_was_move_(false),
73 native_widget_(NULL), 73 native_widget_(NULL),
74 widget_delegate_(NULL), 74 widget_delegate_(NULL),
75 dragged_view_(NULL), 75 dragged_view_(NULL),
76 delete_on_destroy_(false), 76 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET),
77 is_secondary_widget_(true) { 77 is_secondary_widget_(true) {
78 } 78 }
79 79
80 Widget::~Widget() { 80 Widget::~Widget() {
81 DestroyRootView(); 81 DestroyRootView();
82 82
83 if (!delete_on_destroy_) 83 if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET)
84 delete native_widget_; 84 delete native_widget_;
85 } 85 }
86 86
87 // static 87 // static
88 void Widget::SetPureViews(bool pure) { 88 void Widget::SetPureViews(bool pure) {
89 use_pure_views = pure; 89 use_pure_views = pure;
90 } 90 }
91 91
92 // static 92 // static
93 bool Widget::IsPureViews() { 93 bool Widget::IsPureViews() {
94 return use_pure_views; 94 return use_pure_views;
95 } 95 }
96 96
97 void Widget::Init(const InitParams& params) { 97 void Widget::Init(const InitParams& params) {
98 delete_on_destroy_ = params.delete_on_destroy; 98 ownership_ = params.ownership;
99 native_widget_ = 99 native_widget_ =
100 params.native_widget ? params.native_widget 100 params.native_widget ? params.native_widget
101 : NativeWidget::CreateNativeWidget(this); 101 : NativeWidget::CreateNativeWidget(this);
102 GetRootView(); 102 GetRootView();
103 default_theme_provider_.reset(new DefaultThemeProvider); 103 default_theme_provider_.reset(new DefaultThemeProvider);
104 if (params.type == InitParams::TYPE_MENU) 104 if (params.type == InitParams::TYPE_MENU)
105 is_mouse_button_pressed_ = native_widget_->IsMouseButtonDown(); 105 is_mouse_button_pressed_ = native_widget_->IsMouseButtonDown();
106 native_widget_->InitNativeWidget(params); 106 native_widget_->InitNativeWidget(params);
107 } 107 }
108 108
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget(); 518 gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget();
519 if (widget != gfx::kNullAcceleratedWidget) 519 if (widget != gfx::kNullAcceleratedWidget)
520 compositor_ = ui::Compositor::Create(widget); 520 compositor_ = ui::Compositor::Create(widget);
521 } 521 }
522 522
523 bool Widget::ShouldReleaseCaptureOnMouseReleased() const { 523 bool Widget::ShouldReleaseCaptureOnMouseReleased() const {
524 return true; 524 return true;
525 } 525 }
526 526
527 } // namespace views 527 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698