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

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

Issue 1310183009: Add ability for Widgets to override the DefaultThemeProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only Set ThemeProvider on Top Level Widget Created 5 years, 3 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
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/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 mirror_origin_in_rtl(false), 116 mirror_origin_in_rtl(false),
117 shadow_type(SHADOW_TYPE_DEFAULT), 117 shadow_type(SHADOW_TYPE_DEFAULT),
118 remove_standard_frame(false), 118 remove_standard_frame(false),
119 use_system_default_icon(false), 119 use_system_default_icon(false),
120 show_state(ui::SHOW_STATE_DEFAULT), 120 show_state(ui::SHOW_STATE_DEFAULT),
121 parent(NULL), 121 parent(NULL),
122 native_widget(NULL), 122 native_widget(NULL),
123 desktop_window_tree_host(NULL), 123 desktop_window_tree_host(NULL),
124 layer_type(ui::LAYER_TEXTURED), 124 layer_type(ui::LAYER_TEXTURED),
125 context(NULL), 125 context(NULL),
126 force_show_in_taskbar(false) { 126 force_show_in_taskbar(false),
127 theme_provider(nullptr) {
127 } 128 }
128 129
129 Widget::InitParams::InitParams(Type type) 130 Widget::InitParams::InitParams(Type type)
130 : type(type), 131 : type(type),
131 delegate(NULL), 132 delegate(NULL),
132 child(false), 133 child(false),
133 opacity(INFER_OPACITY), 134 opacity(INFER_OPACITY),
134 accept_events(true), 135 accept_events(true),
135 activatable(ACTIVATABLE_DEFAULT), 136 activatable(ACTIVATABLE_DEFAULT),
136 keep_on_top(type == TYPE_MENU || type == TYPE_DRAG), 137 keep_on_top(type == TYPE_MENU || type == TYPE_DRAG),
137 visible_on_all_workspaces(false), 138 visible_on_all_workspaces(false),
138 ownership(NATIVE_WIDGET_OWNS_WIDGET), 139 ownership(NATIVE_WIDGET_OWNS_WIDGET),
139 mirror_origin_in_rtl(false), 140 mirror_origin_in_rtl(false),
140 shadow_type(SHADOW_TYPE_DEFAULT), 141 shadow_type(SHADOW_TYPE_DEFAULT),
141 remove_standard_frame(false), 142 remove_standard_frame(false),
142 use_system_default_icon(false), 143 use_system_default_icon(false),
143 show_state(ui::SHOW_STATE_DEFAULT), 144 show_state(ui::SHOW_STATE_DEFAULT),
144 parent(NULL), 145 parent(NULL),
145 native_widget(NULL), 146 native_widget(NULL),
146 desktop_window_tree_host(NULL), 147 desktop_window_tree_host(NULL),
147 layer_type(ui::LAYER_TEXTURED), 148 layer_type(ui::LAYER_TEXTURED),
148 context(NULL), 149 context(NULL),
149 force_show_in_taskbar(false) { 150 force_show_in_taskbar(false),
151 theme_provider(nullptr) {
150 } 152 }
151 153
152 Widget::InitParams::~InitParams() { 154 Widget::InitParams::~InitParams() {
153 } 155 }
154 156
155 //////////////////////////////////////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////////
156 // Widget, public: 158 // Widget, public:
157 159
158 Widget::Widget() 160 Widget::Widget()
159 : native_widget_(NULL), 161 : native_widget_(NULL),
160 widget_delegate_(NULL), 162 widget_delegate_(NULL),
161 non_client_view_(NULL), 163 non_client_view_(NULL),
164 theme_provider_(nullptr),
162 dragged_view_(NULL), 165 dragged_view_(NULL),
163 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET), 166 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET),
164 is_secondary_widget_(true), 167 is_secondary_widget_(true),
165 frame_type_(FRAME_TYPE_DEFAULT), 168 frame_type_(FRAME_TYPE_DEFAULT),
166 disable_inactive_rendering_(false), 169 disable_inactive_rendering_(false),
167 widget_closed_(false), 170 widget_closed_(false),
168 saved_show_state_(ui::SHOW_STATE_DEFAULT), 171 saved_show_state_(ui::SHOW_STATE_DEFAULT),
169 focus_on_creation_(true), 172 focus_on_creation_(true),
170 is_top_level_(false), 173 is_top_level_(false),
171 native_widget_initialized_(false), 174 native_widget_initialized_(false),
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 348 }
346 349
347 widget_delegate_ = params.delegate ? 350 widget_delegate_ = params.delegate ?
348 params.delegate : new DefaultWidgetDelegate(this); 351 params.delegate : new DefaultWidgetDelegate(this);
349 widget_delegate_->set_can_activate(can_activate); 352 widget_delegate_->set_can_activate(can_activate);
350 353
351 ownership_ = params.ownership; 354 ownership_ = params.ownership;
352 native_widget_ = CreateNativeWidget(params.native_widget, this)-> 355 native_widget_ = CreateNativeWidget(params.native_widget, this)->
353 AsNativeWidgetPrivate(); 356 AsNativeWidgetPrivate();
354 root_view_.reset(CreateRootView()); 357 root_view_.reset(CreateRootView());
355 default_theme_provider_.reset(new ui::DefaultThemeProvider); 358 if (in_params.theme_provider && GetTopLevelWidget() == this)
359 theme_provider_ = in_params.theme_provider;
360 else
361 default_theme_provider_.reset(new ui::DefaultThemeProvider);
tdanderson 2015/09/09 17:38:58 nit: newline after line 361
sadrul 2015/09/09 17:56:57 I was thinking this could be more like: theme_p
356 if (params.type == InitParams::TYPE_MENU) { 362 if (params.type == InitParams::TYPE_MENU) {
357 is_mouse_button_pressed_ = 363 is_mouse_button_pressed_ =
358 internal::NativeWidgetPrivate::IsMouseButtonDown(); 364 internal::NativeWidgetPrivate::IsMouseButtonDown();
359 } 365 }
360 native_widget_->InitNativeWidget(params); 366 native_widget_->InitNativeWidget(params);
361 if (RequiresNonClientView(params.type)) { 367 if (RequiresNonClientView(params.type)) {
362 non_client_view_ = new NonClientView; 368 non_client_view_ = new NonClientView;
363 non_client_view_->SetFrameView(CreateNonClientFrameView()); 369 non_client_view_->SetFrameView(CreateNonClientFrameView());
364 // Create the ClientView, add it to the NonClientView and add the 370 // Create the ClientView, add it to the NonClientView and add the
365 // NonClientView to the RootView. This will cause everything to be parented. 371 // NonClientView to the RootView. This will cause everything to be parented.
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 const View* Widget::GetRootView() const { 743 const View* Widget::GetRootView() const {
738 return root_view_.get(); 744 return root_view_.get();
739 } 745 }
740 746
741 bool Widget::IsVisible() const { 747 bool Widget::IsVisible() const {
742 return native_widget_->IsVisible(); 748 return native_widget_->IsVisible();
743 } 749 }
744 750
745 ui::ThemeProvider* Widget::GetThemeProvider() const { 751 ui::ThemeProvider* Widget::GetThemeProvider() const {
746 const Widget* root_widget = GetTopLevelWidget(); 752 const Widget* root_widget = GetTopLevelWidget();
747 if (root_widget && root_widget != this) { 753 if (root_widget && root_widget != this)
748 // Attempt to get the theme provider, and fall back to the default theme 754 return root_widget->GetThemeProvider();
749 // provider if not found. 755 return theme_provider_ ? theme_provider_ : default_theme_provider_.get();
750 ui::ThemeProvider* provider = root_widget->GetThemeProvider();
751 if (provider)
752 return provider;
753
754 provider = root_widget->default_theme_provider_.get();
755 if (provider)
756 return provider;
757 }
758 return default_theme_provider_.get();
759 } 756 }
760 757
761 const ui::NativeTheme* Widget::GetNativeTheme() const { 758 const ui::NativeTheme* Widget::GetNativeTheme() const {
762 return native_widget_->GetNativeTheme(); 759 return native_widget_->GetNativeTheme();
763 } 760 }
764 761
765 FocusManager* Widget::GetFocusManager() { 762 FocusManager* Widget::GetFocusManager() {
766 Widget* toplevel_widget = GetTopLevelWidget(); 763 Widget* toplevel_widget = GetTopLevelWidget();
767 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; 764 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL;
768 } 765 }
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 1488
1492 //////////////////////////////////////////////////////////////////////////////// 1489 ////////////////////////////////////////////////////////////////////////////////
1493 // internal::NativeWidgetPrivate, NativeWidget implementation: 1490 // internal::NativeWidgetPrivate, NativeWidget implementation:
1494 1491
1495 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1492 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1496 return this; 1493 return this;
1497 } 1494 }
1498 1495
1499 } // namespace internal 1496 } // namespace internal
1500 } // namespace views 1497 } // namespace views
OLDNEW
« chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc ('K') | « ui/views/widget/widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698