diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-28 17:58:09 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-28 17:58:09 +0000 |
commit | 0ef6c772205144c383c8956218425bb160a5ecd8 (patch) | |
tree | 052314732e2318bf090fbe631737e66ed79c87c5 | |
parent | d2ceb4e7fe001e55d540784abac24620dc6b4a4a (diff) | |
download | chromium_src-0ef6c772205144c383c8956218425bb160a5ecd8.zip chromium_src-0ef6c772205144c383c8956218425bb160a5ecd8.tar.gz chromium_src-0ef6c772205144c383c8956218425bb160a5ecd8.tar.bz2 |
Convert more WidgetWin/WidgetGtk creations to use a new cross-platform static ctor on Widget: CreateWidget().
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/6732028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79586 0039d316-1c4b-4281-b951-d872f2087c98
45 files changed, 221 insertions, 219 deletions
diff --git a/chrome/browser/chromeos/frame/panel_controller.cc b/chrome/browser/chromeos/frame/panel_controller.cc index 74879d7..93a2756 100644 --- a/chrome/browser/chromeos/frame/panel_controller.cc +++ b/chrome/browser/chromeos/frame/panel_controller.cc @@ -27,7 +27,7 @@ #include "views/events/event.h" #include "views/painter.h" #include "views/view.h" -#include "views/widget/widget_gtk.h" +#include "views/widget/widget.h" #include "views/window/window.h" namespace chromeos { @@ -123,8 +123,9 @@ void PanelController::Init(bool initial_focus, WmIpcPanelUserResizeType resize_type) { gfx::Rect title_bounds(0, 0, window_bounds.width(), kTitleHeight); - title_window_ = new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW); - title_window_->MakeTransparent(); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); + params.transparent = true; + title_window_ = views::Widget::CreateWidget(params); title_window_->Init(NULL, title_bounds); gtk_widget_set_size_request(title_window_->GetNativeView(), title_bounds.width(), title_bounds.height()); diff --git a/chrome/browser/chromeos/frame/panel_controller.h b/chrome/browser/chromeos/frame/panel_controller.h index ec27bf2..ff23cfa 100644 --- a/chrome/browser/chromeos/frame/panel_controller.h +++ b/chrome/browser/chromeos/frame/panel_controller.h @@ -21,7 +21,7 @@ class ImageButton; class ImageView; class Label; class MouseEvent; -class WidgetGtk; +class Widget; } namespace chromeos { @@ -120,7 +120,7 @@ class PanelController { XID panel_xid_; // Views object representing title. - views::WidgetGtk* title_window_; + views::Widget* title_window_; // Gtk object representing title. GtkWidget* title_; // X id representing title. diff --git a/chrome/browser/chromeos/input_method/candidate_window.cc b/chrome/browser/chromeos/input_method/candidate_window.cc index eec075a..5146a7c 100644 --- a/chrome/browser/chromeos/input_method/candidate_window.cc +++ b/chrome/browser/chromeos/input_method/candidate_window.cc @@ -804,8 +804,8 @@ void CandidateWindowView::HideLookupTable() { // First, in the following scenario, it seems that the Views popup window does // not release mouse/keyboard grab even after it gets hidden. // - // 1. create a popup window by views::Widget::CreatePopupWidget() with the - // views::Widget::AcceptEvents flag. + // 1. create a popup window by views::Widget::CreateWidget() with the + // accept_events flag set to true on the CreateParams. // 2. press a mouse button on the window. // 3. before releasing the mouse button, Hide() the window. // 4. release the button. @@ -1285,7 +1285,7 @@ bool CandidateWindowController::Impl::Init() { void CandidateWindowController::Impl::CreateView() { // Create a non-decorated frame. - frame_.reset(views::Widget::CreatePopupWidget( + frame_.reset(views::Widget::CreateWidget( views::Widget::CreateParams(views::Widget::CreateParams::TYPE_POPUP))); // The size is initially zero. frame_->Init(NULL, gfx::Rect(0, 0)); diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc index 53c8760..3a6a034 100644 --- a/chrome/browser/chromeos/login/background_view.cc +++ b/chrome/browser/chromeos/login/background_view.cc @@ -46,6 +46,7 @@ #include <X11/cursorfont.h> // NOLINT #include <X11/Xcursor/Xcursor.h> // NOLINT +using views::Widget; using views::WidgetGtk; namespace { @@ -166,7 +167,8 @@ views::Widget* BackgroundView::CreateWindowContainingView( BackgroundView** view) { ResetXCursor(); - WidgetGtk* window = new WidgetGtk(WidgetGtk::TYPE_WINDOW); + Widget* window = Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_WINDOW)); window->Init(NULL, bounds); *view = new BackgroundView(); (*view)->Init(background_url); diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc index c7ea662..206ed74 100644 --- a/chrome/browser/chromeos/login/helper.cc +++ b/chrome/browser/chromeos/login/helper.cc @@ -108,12 +108,11 @@ void ThrobberHostView::StartThrobber() { throbber->set_stop_delay_ms(0); gfx::Rect throbber_bounds = CalculateThrobberBounds(throbber); - views::WidgetGtk* widget_gtk = - new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW); - widget_gtk->make_transient_to_parent(); - widget_gtk->MakeTransparent(); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); + params.transparent = true; + throbber_widget_ = views::Widget::CreateWidget(params); + static_cast<views::WidgetGtk*>(throbber_widget_)->make_transient_to_parent(); - throbber_widget_ = widget_gtk; throbber_bounds.Offset(host_view_->GetScreenBounds().origin()); throbber_widget_->Init(host_gtk_window, throbber_bounds); throbber_widget_->SetContentsView(throbber); diff --git a/chrome/browser/chromeos/login/user_controller.cc b/chrome/browser/chromeos/login/user_controller.cc index a151502..118f197 100644 --- a/chrome/browser/chromeos/login/user_controller.cc +++ b/chrome/browser/chromeos/login/user_controller.cc @@ -34,6 +34,7 @@ using views::ColumnSet; using views::GridLayout; +using views::Widget; using views::WidgetGtk; namespace chromeos { @@ -64,7 +65,7 @@ class ControlsWindow : public WidgetGtk { } private: - // WidgetGtk overrrides: + // WidgetGtk overrides: virtual void SetInitialFocus() { if (initial_focus_view_) initial_focus_view_->RequestFocus(); @@ -98,7 +99,7 @@ class ClickNotifyingWidget : public views::WidgetGtk { DISALLOW_COPY_AND_ASSIGN(ClickNotifyingWidget); }; -void CloseWindow(views::WidgetGtk* window) { +void CloseWindow(views::Widget* window) { if (!window) return; window->set_widget_delegate(NULL); @@ -439,8 +440,9 @@ void UserController::CreateBorderWindow(int index, height += 2 * kBorderSize + kUserImageSize + kVerticalIntervalSize; } - border_window_ = new WidgetGtk(WidgetGtk::TYPE_WINDOW); - border_window_->MakeTransparent(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.transparent = true; + border_window_ = Widget::CreateWidget(params); border_window_->Init(NULL, gfx::Rect(0, 0, width, height)); if (!is_new_user_) { views::View* background_view = new views::View(); diff --git a/chrome/browser/chromeos/login/user_controller.h b/chrome/browser/chromeos/login/user_controller.h index 28250a1..738b214 100644 --- a/chrome/browser/chromeos/login/user_controller.h +++ b/chrome/browser/chromeos/login/user_controller.h @@ -175,7 +175,7 @@ class UserController : public views::WidgetDelegate, // A window is used to represent the individual chunks. views::WidgetGtk* controls_window_; views::WidgetGtk* image_window_; - views::WidgetGtk* border_window_; + views::Widget* border_window_; views::WidgetGtk* label_window_; views::WidgetGtk* unselected_label_window_; diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index d9fdcf1..0bde193 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -570,27 +570,27 @@ void WizardController::InitiateOOBEUpdate() { /////////////////////////////////////////////////////////////////////////////// // WizardController, private: -views::WidgetGtk* WizardController::CreateScreenWindow( +views::Widget* WizardController::CreateScreenWindow( const gfx::Rect& bounds, bool initial_show) { - views::WidgetGtk* window = - new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW); - widget_ = window; - window->MakeTransparent(); + views::Widget::CreateParams widget_params( + views::Widget::CreateParams::TYPE_WINDOW); + widget_params.transparent = true; + widget_ = views::Widget::CreateWidget(widget_params); // Window transparency makes background flicker through controls that // are constantly updating its contents (like image view with video // stream). Hence enabling double buffer. - window->EnableDoubleBuffer(true); - window->Init(NULL, bounds); + static_cast<views::WidgetGtk*>(widget_)->EnableDoubleBuffer(true); + widget_->Init(NULL, bounds); std::vector<int> params; // For initial show WM would animate background window. // Otherwise it stays unchaged. params.push_back(initial_show); chromeos::WmIpc::instance()->SetWindowType( - window->GetNativeView(), + widget_->GetNativeView(), chromeos::WM_IPC_WINDOW_LOGIN_GUEST, ¶ms); - window->SetContentsView(contents_); - return window; + widget_->SetContentsView(contents_); + return widget_; } gfx::Rect WizardController::GetWizardScreenBounds(int screen_width, @@ -616,7 +616,7 @@ void WizardController::ShowCurrentScreen() { smooth_show_timer_.Stop(); bool force_widget_show = false; - views::WidgetGtk* window = NULL; + views::Widget* window = NULL; gfx::Rect current_bounds; if (widget_) diff --git a/chrome/browser/chromeos/login/wizard_controller.h b/chrome/browser/chromeos/login/wizard_controller.h index e58c99958..4a14c7d 100644 --- a/chrome/browser/chromeos/login/wizard_controller.h +++ b/chrome/browser/chromeos/login/wizard_controller.h @@ -181,8 +181,8 @@ class WizardController : public chromeos::ScreenObserver, // Creates wizard screen window with the specified |bounds|. // If |initial_show| initial animation (window & background) is shown. // Otherwise only window is animated. - views::WidgetGtk* CreateScreenWindow(const gfx::Rect& bounds, - bool initial_show); + views::Widget* CreateScreenWindow(const gfx::Rect& bounds, + bool initial_show); // Returns bounds for the wizard screen host window in screen coordinates. // Calculates bounds using screen_bounds_. diff --git a/chrome/browser/chromeos/notifications/balloon_view.cc b/chrome/browser/chromeos/notifications/balloon_view.cc index 08dadc6..cac419a 100644 --- a/chrome/browser/chromeos/notifications/balloon_view.cc +++ b/chrome/browser/chromeos/notifications/balloon_view.cc @@ -266,12 +266,14 @@ void BalloonViewImpl::Layout() { void BalloonViewImpl::ViewHierarchyChanged( bool is_add, View* parent, View* child) { if (is_add && GetWidget() && !control_view_host_.get() && controls_) { - control_view_host_.reset( - new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD)); - control_view_host_->EnableDoubleBuffer(true); + views::Widget::CreateParams params( + views::Widget::CreateParams::TYPE_CONTROL); + params.delete_on_destroy = false; + control_view_host_.reset(views::Widget::CreateWidget(params)); + static_cast<views::WidgetGtk*>(control_view_host_.get())-> + EnableDoubleBuffer(true); control_view_host_->Init(GetParentNativeView(), gfx::Rect()); NotificationControlView* control = new NotificationControlView(this); - control_view_host_->set_delete_on_destroy(false); control_view_host_->SetContentsView(control); } if (!is_add && this == child && control_view_host_.get() && controls_) { diff --git a/chrome/browser/chromeos/notifications/balloon_view.h b/chrome/browser/chromeos/notifications/balloon_view.h index 6002312..a7a8e0f 100644 --- a/chrome/browser/chromeos/notifications/balloon_view.h +++ b/chrome/browser/chromeos/notifications/balloon_view.h @@ -25,7 +25,7 @@ class Menu2; class MenuButton; class MouseEvent; class TextButton; -class WidgetGtk; +class Widget; } // namespace views class Notification; @@ -113,7 +113,7 @@ class BalloonViewImpl : public BalloonView, ScopedRunnableMethodFactory<BalloonViewImpl> method_factory_; // A widget for ControlView. - scoped_ptr<views::WidgetGtk> control_view_host_; + scoped_ptr<views::Widget> control_view_host_; bool stale_; NotificationRegistrar notification_registrar_; diff --git a/chrome/browser/chromeos/panels/panel_scroller.cc b/chrome/browser/chromeos/panels/panel_scroller.cc index 93ba163..233fc96 100644 --- a/chrome/browser/chromeos/panels/panel_scroller.cc +++ b/chrome/browser/chromeos/panels/panel_scroller.cc @@ -12,7 +12,7 @@ #include "chrome/browser/chromeos/panels/panel_scroller_container.h" #include "chrome/browser/chromeos/panels/panel_scroller_header.h" #include "ui/gfx/canvas.h" -#include "views/widget/widget_gtk.h" +#include "views/widget/widget.h" struct PanelScroller::Panel { PanelScrollerHeader* header; @@ -80,9 +80,8 @@ PanelScroller::~PanelScroller() { // static PanelScroller* PanelScroller::CreateWindow() { - views::WidgetGtk* widget = - new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW); - widget->set_delete_on_destroy(true); + views::Widget* widget = views::Widget::CreateWidget( + views::Widget::CreateParams(views::Widget::CreateParams::TYPE_WINDOW)); widget->Init(NULL, gfx::Rect(0, 0, 100, 800)); PanelScroller* scroller = new PanelScroller(); diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc index 311c832..7d81f51 100644 --- a/chrome/browser/first_run/first_run_win.cc +++ b/chrome/browser/first_run/first_run_win.cc @@ -58,7 +58,7 @@ #include "views/layout/grid_layout.h" #include "views/layout/layout_constants.h" #include "views/widget/root_view.h" -#include "views/widget/widget_win.h" +#include "views/widget/widget.h" #include "views/window/window.h" namespace { @@ -594,19 +594,18 @@ class TryChromeDialog : public views::ButtonListener, gfx::Size icon_size = icon->GetPreferredSize(); // An approximate window size. After Layout() we'll get better bounds. - gfx::Rect pos(310, 160); - views::WidgetWin* popup = new views::WidgetWin(); - if (!popup) { + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.can_activate = true; + popup_ = views::Widget::CreateWidget(params); + if (!popup_) { NOTREACHED(); return Upgrade::TD_DIALOG_ERROR; } - views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); - params.can_activate = true; - popup->SetCreateParams(params); - popup->Init(NULL, pos); + gfx::Rect pos(310, 160); + popup_->Init(NULL, pos); - views::RootView* root_view = popup->GetRootView(); + views::RootView* root_view = popup_->GetRootView(); // The window color is a tiny bit off-white. root_view->set_background( views::Background::CreateSolidBackground(0xfc, 0xfc, 0xfc)); @@ -726,16 +725,15 @@ class TryChromeDialog : public views::ButtonListener, gfx::Size preferred = layout->GetPreferredSize(root_view); pos = ComputeWindowPosition(preferred.width(), preferred.height(), base::i18n::IsRTL()); - popup->SetBounds(pos); + popup_->SetBounds(pos); // Carve the toast shape into the window. - SetToastRegion(popup->GetNativeView(), + SetToastRegion(popup_->GetNativeView(), preferred.width(), preferred.height()); - popup_ = popup; // Time to show the window in a modal loop. We don't want this chrome // instance trying to serve WM_COPYDATA requests, as we'll surely crash. - process_singleton->Lock(popup->GetNativeView()); + process_singleton->Lock(popup_->GetNativeView()); popup_->Show(); MessageLoop::current()->Run(); process_singleton->Unlock(); @@ -817,7 +815,7 @@ class TryChromeDialog : public views::ButtonListener, // We don't own any of this pointers. The |popup_| owns itself and owns // the other views. - views::WidgetWin* popup_; + views::Widget* popup_; views::RadioButton* try_chrome_; views::RadioButton* kill_chrome_; Upgrade::TryResult result_; diff --git a/chrome/browser/ui/views/dom_view_browsertest.cc b/chrome/browser/ui/views/dom_view_browsertest.cc index a4e77c1..bd5dc14 100644 --- a/chrome/browser/ui/views/dom_view_browsertest.cc +++ b/chrome/browser/ui/views/dom_view_browsertest.cc @@ -16,9 +16,9 @@ class DOMViewTest : public InProcessBrowserTest { Widget* CreatePopupWindow() { Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); params.mirror_origin_in_rtl = false; - Widget* window = Widget::CreatePopupWidget(params); - window->Init(NULL, gfx::Rect(0, 0, 400, 400)); - return window; + Widget* widget = Widget::CreateWidget(params); + widget->Init(NULL, gfx::Rect(0, 0, 400, 400)); + return widget; } }; diff --git a/chrome/browser/ui/views/download_started_animation_win.cc b/chrome/browser/ui/views/download_started_animation_win.cc index 292fe6f..602f8e7 100644 --- a/chrome/browser/ui/views/download_started_animation_win.cc +++ b/chrome/browser/ui/views/download_started_animation_win.cc @@ -13,7 +13,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/rect.h" #include "views/controls/image_view.h" -#include "views/widget/widget_win.h" +#include "views/widget/widget.h" // How long to spend moving downwards and fading out after waiting. static const int kMoveTimeMs = 600; @@ -55,7 +55,7 @@ class DownloadStartedAnimationWin : public ui::LinearAnimation, const NotificationDetails& details); // We use a HWND for the popup so that it may float above any HWNDs in our UI. - views::WidgetWin* popup_; + views::Widget* popup_; // The content area holding us. TabContents* tab_contents_; @@ -102,11 +102,10 @@ DownloadStartedAnimationWin::DownloadStartedAnimationWin( SetImage(kDownloadImage); gfx::Rect rc(0, 0, 0, 0); - popup_ = new views::WidgetWin; views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; - popup_->SetCreateParams(params); + popup_ = views::Widget::CreateWidget(params); popup_->SetOpacity(0x00); popup_->Init(tab_contents_->GetNativeView(), rc); popup_->SetContentsView(this); @@ -125,12 +124,12 @@ void DownloadStartedAnimationWin::Reposition() { gfx::Size size = GetPreferredSize(); int x = base::i18n::IsRTL() ? tab_contents_bounds_.right() - size.width() : tab_contents_bounds_.x(); - popup_->MoveWindow( + popup_->SetBounds(gfx::Rect( x, static_cast<int>(tab_contents_bounds_.bottom() - size.height() - size.height() * (1 - GetCurrentValue())), size.width(), - size.height()); + size.height())); } void DownloadStartedAnimationWin::Close() { diff --git a/chrome/browser/ui/views/dropdown_bar_host_gtk.cc b/chrome/browser/ui/views/dropdown_bar_host_gtk.cc index b0da8ad..a954f5d 100644 --- a/chrome/browser/ui/views/dropdown_bar_host_gtk.cc +++ b/chrome/browser/ui/views/dropdown_bar_host_gtk.cc @@ -8,7 +8,7 @@ #include "chrome/browser/ui/views/frame/browser_view.h" #include "content/browser/tab_contents/tab_contents.h" -#include "views/widget/widget_gtk.h" +#include "views/widget/widget.h" #include "views/controls/textfield/textfield.h" #if defined(TOUCH_UI) @@ -16,10 +16,10 @@ #endif views::Widget* DropdownBarHost::CreateHost() { - views::WidgetGtk* host = new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); // We own the host. - host->set_delete_on_destroy(false); - return host; + params.delete_on_destroy = false; + return views::Widget::CreateWidget(params); } void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos, diff --git a/chrome/browser/ui/views/dropdown_bar_host_win.cc b/chrome/browser/ui/views/dropdown_bar_host_win.cc index 23fe664..33e8a60 100644 --- a/chrome/browser/ui/views/dropdown_bar_host_win.cc +++ b/chrome/browser/ui/views/dropdown_bar_host_win.cc @@ -24,7 +24,7 @@ NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent( views::Widget* DropdownBarHost::CreateHost() { views::WidgetWin* widget = new views::WidgetWin(); - views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CHILD); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); // Don't let WidgetWin manage our lifetime. We want our lifetime to // coincide with TabContents. params.delete_on_destroy = false; diff --git a/chrome/browser/ui/views/extensions/extension_popup.cc b/chrome/browser/ui/views/extensions/extension_popup.cc index 5d64b84..4cb0c8e 100644 --- a/chrome/browser/ui/views/extensions/extension_popup.cc +++ b/chrome/browser/ui/views/extensions/extension_popup.cc @@ -93,18 +93,14 @@ ExtensionPopup::ExtensionPopup(ExtensionHost* host, relative_to_.set_origin(origin); // The bubble chrome requires a separate window, so construct it here. - gfx::NativeView native_window = frame->GetNativeView(); -#if defined(OS_LINUX) - border_widget_ = new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW); - static_cast<views::WidgetGtk*>(border_widget_)->MakeTransparent(); - static_cast<views::WidgetGtk*>(border_widget_)->make_transient_to_parent(); -#else Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; - border_widget_ = Widget::CreatePopupWidget(params); + border_widget_ = Widget::CreateWidget(params); +#if defined(OS_LINUX) + static_cast<views::WidgetGtk*>(border_widget_)->make_transient_to_parent(); #endif - border_widget_->Init(native_window, bounds()); + border_widget_->Init(frame->GetNativeView(), bounds()); #if defined(OS_CHROMEOS) { vector<int> params; diff --git a/chrome/browser/ui/views/frame/contents_container.cc b/chrome/browser/ui/views/frame/contents_container.cc index afad3ba..ac90913 100644 --- a/chrome/browser/ui/views/frame/contents_container.cc +++ b/chrome/browser/ui/views/frame/contents_container.cc @@ -154,7 +154,7 @@ void ContentsContainer::CreateOverlay(int initial_opacity) { views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; - active_overlay_ = views::Widget::CreatePopupWidget(params); + active_overlay_ = views::Widget::CreateWidget(params); active_overlay_->SetOpacity(initial_opacity); gfx::Point screen_origin; views::View::ConvertPointToScreen(active_, &screen_origin); diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble.cc b/chrome/browser/ui/views/fullscreen_exit_bubble.cc index 0c281e3..bd7e31c 100644 --- a/chrome/browser/ui/views/fullscreen_exit_bubble.cc +++ b/chrome/browser/ui/views/fullscreen_exit_bubble.cc @@ -135,7 +135,7 @@ FullscreenExitBubble::FullscreenExitBubble( params.transparent = true; params.can_activate = false; params.delete_on_destroy = false; - popup_ = views::Widget::CreatePopupWidget(params); + popup_ = views::Widget::CreateWidget(params); popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity)); popup_->Init(frame->GetNativeView(), GetPopupRect(false)); popup_->SetContentsView(view_); diff --git a/chrome/browser/ui/views/generic_info_view_unittest.cc b/chrome/browser/ui/views/generic_info_view_unittest.cc index 8f7cceb..bfefb72 100644 --- a/chrome/browser/ui/views/generic_info_view_unittest.cc +++ b/chrome/browser/ui/views/generic_info_view_unittest.cc @@ -25,7 +25,8 @@ using namespace views; class GenericInfoViewTest : public testing::Test { public: Widget* CreateWidget() { - return new WidgetWin(); + return views::Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_POPUP)); } private: MessageLoopForUI message_loop_; @@ -35,9 +36,9 @@ TEST_F(GenericInfoViewTest, GenericInfoView) { const string16 kName = ASCIIToUTF16("Name"); const string16 kValue = ASCIIToUTF16("Value"); - Widget* window = CreateWidget(); - static_cast<WidgetWin*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100)); - RootView* root_view = window->GetRootView(); + Widget* widget = CreateWidget(); + widget->Init(NULL, gfx::Rect(0, 0, 100, 100)); + RootView* root_view = widget->GetRootView(); GenericInfoView* view1 = new GenericInfoView(1); root_view->AddChildView(view1); @@ -60,6 +61,6 @@ TEST_F(GenericInfoViewTest, GenericInfoView) { string16 product_desc = l10n_util::GetStringUTF16(IDS_PRODUCT_DESCRIPTION); EXPECT_EQ(product_name, view2->name_views_[0]->GetText()); EXPECT_EQ(product_desc, view2->name_views_[1]->GetText()); - window->CloseNow(); + widget->CloseNow(); } #endif // OS_WIN diff --git a/chrome/browser/ui/views/notifications/balloon_view.cc b/chrome/browser/ui/views/notifications/balloon_view.cc index 91864f3..6118ca3 100644 --- a/chrome/browser/ui/views/notifications/balloon_view.cc +++ b/chrome/browser/ui/views/notifications/balloon_view.cc @@ -317,14 +317,14 @@ void BalloonViewImpl::Show(Balloon* balloon) { html_contents_->SetPreferredSize(gfx::Size(10000, 10000)); Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); params.mirror_origin_in_rtl = false; - html_container_ = Widget::CreatePopupWidget(params); + html_container_ = Widget::CreateWidget(params); html_container_->SetAlwaysOnTop(true); html_container_->Init(NULL, contents_rect); html_container_->SetContentsView(html_contents_->view()); gfx::Rect balloon_rect(x(), y(), GetTotalWidth(), GetTotalHeight()); params.transparent = true; - frame_container_ = Widget::CreatePopupWidget(params); + frame_container_ = Widget::CreateWidget(params); frame_container_->set_widget_delegate(this); frame_container_->SetAlwaysOnTop(true); frame_container_->Init(NULL, balloon_rect); diff --git a/chrome/browser/ui/views/status_bubble_views.cc b/chrome/browser/ui/views/status_bubble_views.cc index 1af27c5..e996b3b 100644 --- a/chrome/browser/ui/views/status_bubble_views.cc +++ b/chrome/browser/ui/views/status_bubble_views.cc @@ -561,7 +561,7 @@ void StatusBubbleViews::Init() { params.transparent = true; params.accept_events = false; params.delete_on_destroy = false; - popup_.reset(Widget::CreatePopupWidget(params)); + popup_.reset(Widget::CreateWidget(params)); views::Widget* frame = base_view_->GetWidget(); if (!view_) view_ = new StatusView(this, popup_.get(), frame->GetThemeProvider()); diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_win.cc index 1deeaf1..3164300 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_win.cc @@ -45,18 +45,19 @@ using WebKit::WebInputEvent; // // See: http://crbug.com/16476 static HWND GetHiddenTabHostWindow() { - static views::WidgetWin* window = NULL; + static views::Widget* widget = NULL; - if (!window) { - window = new views::WidgetWin(); + if (!widget) { + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + widget = views::Widget::CreateWidget(params); + widget->Init(NULL, gfx::Rect()); // If a background window requests focus, the hidden tab host will // be activated to focus the tab. Use WS_DISABLED to prevent // this. - window->set_window_style(WS_POPUP | WS_DISABLED); - window->Init(NULL, gfx::Rect()); + EnableWindow(widget->GetNativeView(), FALSE); } - return window->hwnd(); + return widget->GetNativeView(); } // static diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc index 45ae48b..6b9e8b2 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc @@ -211,20 +211,19 @@ class DraggedTabController::DockDisplayer : public ui::AnimationDelegate { hidden_(false), in_enable_area_(info.in_enable_area()) { #if defined(OS_WIN) - views::WidgetWin* popup = new views::WidgetWin; - popup_ = popup; - popup->set_window_style(WS_POPUP); - popup->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW | - WS_EX_TOPMOST); - popup->SetOpacity(0x00); - popup->Init(NULL, info.GetPopupRect()); - popup->SetContentsView(new DockView(info.type())); + // TODO(sky): This should "just work" on Gtk now. + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.transparent = true; + params.keep_on_top = true; + popup_ = views::Widget::CreateWidget(params); + popup_->SetOpacity(0x00); + popup_->Init(NULL, info.GetPopupRect()); + popup_->SetContentsView(new DockView(info.type())); if (info.in_enable_area()) animation_.Reset(1); else animation_.Show(); - popup->SetWindowPos(HWND_TOP, 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOMOVE | SWP_SHOWWINDOW); + popup_->Show(); #else NOTIMPLEMENTED(); #endif diff --git a/chrome/browser/ui/views/tabs/dragged_tab_view.cc b/chrome/browser/ui/views/tabs/dragged_tab_view.cc index 8d6231d..94d16d0 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_view.cc @@ -38,28 +38,23 @@ DraggedTabView::DraggedTabView(const std::vector<views::View*>& renderers, contents_size_(contents_size) { set_parent_owned(false); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.transparent = true; + params.keep_on_top = true; + params.delete_on_destroy = false; + container_.reset(views::Widget::CreateWidget(params)); #if defined(OS_WIN) - container_.reset(new views::WidgetWin); - container_->set_delete_on_destroy(false); - container_->set_window_style(WS_POPUP); - container_->set_window_ex_style( - WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW); - container_->set_can_update_layered_window(false); - container_->Init(NULL, gfx::Rect(0, 0, 0, 0)); - container_->SetContentsView(this); + static_cast<views::WidgetWin*>(container_.get())-> + set_can_update_layered_window(false); BOOL drag; if ((::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, &drag, 0) != 0) && (drag == FALSE)) { show_contents_on_drag_ = false; } -#else - container_.reset(new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP)); - container_->MakeTransparent(); - container_->set_delete_on_destroy(false); +#endif container_->Init(NULL, gfx::Rect(0, 0, 0, 0)); container_->SetContentsView(this); -#endif } DraggedTabView::~DraggedTabView() { @@ -85,9 +80,10 @@ void DraggedTabView::MoveTo(const gfx::Point& screen_point) { ScaleValue(mouse_tab_offset_.y()); #if defined(OS_WIN) + // TODO(beng): make this cross-platform int show_flags = container_->IsVisible() ? SWP_NOZORDER : SWP_SHOWWINDOW; - container_->SetWindowPos(HWND_TOP, x, y, 0, 0, - SWP_NOSIZE | SWP_NOACTIVATE | show_flags); + SetWindowPos(container_->GetNativeView(), HWND_TOP, x, y, 0, 0, + SWP_NOSIZE | SWP_NOACTIVATE | show_flags); #else gfx::Rect bounds = container_->GetWindowScreenBounds(); container_->SetBounds(gfx::Rect(x, y, bounds.width(), bounds.height())); diff --git a/chrome/browser/ui/views/tabs/dragged_tab_view.h b/chrome/browser/ui/views/tabs/dragged_tab_view.h index 1646de9..8c3eea8 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_view.h +++ b/chrome/browser/ui/views/tabs/dragged_tab_view.h @@ -71,11 +71,7 @@ class DraggedTabView : public views::View { int ScaleValue(int value); // The window that contains the DraggedTabView. -#if defined(OS_WIN) - scoped_ptr<views::WidgetWin> container_; -#elif defined(OS_LINUX) - scoped_ptr<views::WidgetGtk> container_; -#endif + scoped_ptr<views::Widget> container_; // The renderer that paints the Tab shape. std::vector<views::View*> renderers_; diff --git a/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc b/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc index 07bf171..ea53148 100644 --- a/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc +++ b/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc @@ -8,7 +8,8 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/point.h" -#include "views/widget/widget_win.h" +#include "ui/gfx/rect.h" +#include "views/widget/widget.h" namespace { @@ -144,17 +145,15 @@ void NativeViewPhotoboothWin::CreateCaptureWindow(HWND initial_hwnd) { // associated HWND to it. Note that the details are important here, see below // for further comments. // - CRect contents_rect; + RECT contents_rect; GetClientRect(initial_hwnd, &contents_rect); gfx::Point window_position = GetCaptureWindowPosition(); gfx::Rect capture_bounds(window_position.x(), window_position.y(), - contents_rect.Width(), contents_rect.Height()); - capture_window_ = new views::WidgetWin; - capture_window_->set_window_style(WS_POPUP); - // WS_EX_TOOLWINDOW ensures the capture window doesn't produce a Taskbar - // button. - capture_window_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW); - capture_window_->Init(NULL, capture_bounds); + contents_rect.right - contents_rect.left, + contents_rect.bottom - contents_rect.top); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.transparent = true; + capture_window_ = views::Widget::CreateWidget(params); // If the capture window isn't visible, blitting from the TabContents' // HWND's DC to the capture bitmap produces blankness. capture_window_->Show(); diff --git a/chrome/browser/ui/views/tabs/native_view_photobooth_win.h b/chrome/browser/ui/views/tabs/native_view_photobooth_win.h index 94cff1b..369d48e 100644 --- a/chrome/browser/ui/views/tabs/native_view_photobooth_win.h +++ b/chrome/browser/ui/views/tabs/native_view_photobooth_win.h @@ -9,7 +9,7 @@ #include "chrome/browser/ui/views/tabs/native_view_photobooth.h" namespace views { -class WidgetWin; +class Widget; } /////////////////////////////////////////////////////////////////////////////// @@ -48,7 +48,7 @@ class NativeViewPhotoboothWin : public NativeViewPhotobooth { void CreateCaptureWindow(HWND initial_hwnd); // The nearly off-screen photo-booth layered window used to hold the HWND. - views::WidgetWin* capture_window_; + views::Widget* capture_window_; // The current HWND being captured. HWND current_hwnd_; diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc index 7a929de..62e194d 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.cc +++ b/chrome/browser/ui/views/tabs/tab_strip.cc @@ -807,15 +807,8 @@ void TabStrip::SetDropIndex(int tab_data_index, bool drop_before) { // Reposition the window. Need to show it too as the window is initially // hidden. - -#if defined(OS_WIN) - drop_info_->arrow_window->SetWindowPos( - HWND_TOPMOST, drop_bounds.x(), drop_bounds.y(), drop_bounds.width(), - drop_bounds.height(), SWP_NOACTIVATE | SWP_SHOWWINDOW); -#else drop_info_->arrow_window->SetBounds(drop_bounds); drop_info_->arrow_window->Show(); -#endif } int TabStrip::GetDropEffect(const views::DropTargetEvent& event) { @@ -842,15 +835,12 @@ TabStrip::DropInfo::DropInfo(int drop_index, bool drop_before, bool point_down) arrow_view = new views::ImageView; arrow_view->SetImage(GetDropArrowImage(point_down)); -#if defined(OS_WIN) - arrow_window = new views::WidgetWin; - arrow_window->set_window_style(WS_POPUP); - arrow_window->set_window_ex_style(WS_EX_TOPMOST | WS_EX_NOACTIVATE | - WS_EX_LAYERED | WS_EX_TRANSPARENT); -#else - arrow_window = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP); - arrow_window->MakeTransparent(); -#endif + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.keep_on_top = true; + params.transparent = true; + params.accept_events = false; + params.can_activate = false; + arrow_window = views::Widget::CreateWidget(params); arrow_window->Init( NULL, gfx::Rect(0, 0, drop_indicator_width, drop_indicator_height)); diff --git a/chrome/browser/ui/views/tabs/tab_strip.h b/chrome/browser/ui/views/tabs/tab_strip.h index 0860ead..52b6968 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.h +++ b/chrome/browser/ui/views/tabs/tab_strip.h @@ -130,12 +130,7 @@ class TabStrip : public BaseTabStrip, bool point_down; // Renders the drop indicator. - // TODO(beng): should be views::Widget. -#if defined(OS_WIN) - views::WidgetWin* arrow_window; -#else - views::WidgetGtk* arrow_window; -#endif + views::Widget* arrow_window; views::ImageView* arrow_view; private: diff --git a/chrome/browser/ui/views/theme_install_bubble_view.cc b/chrome/browser/ui/views/theme_install_bubble_view.cc index ddb2016..a3136aa 100644 --- a/chrome/browser/ui/views/theme_install_bubble_view.cc +++ b/chrome/browser/ui/views/theme_install_bubble_view.cc @@ -74,7 +74,7 @@ ThemeInstallBubbleView::ThemeInstallBubbleView(TabContents* tab_contents) views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; - popup_ = views::Widget::CreatePopupWidget(params); + popup_ = views::Widget::CreateWidget(params); popup_->SetOpacity(0xCC); popup_->Init(tab_contents->GetNativeView(), rc); popup_->SetContentsView(this); diff --git a/ui/gfx/rect.cc b/ui/gfx/rect.cc index ceb6aee..5413711 100644 --- a/ui/gfx/rect.cc +++ b/ui/gfx/rect.cc @@ -54,14 +54,14 @@ Rect::Rect(const gfx::Point& origin, const gfx::Size& size) #if defined(OS_WIN) Rect::Rect(const RECT& r) : origin_(r.left, r.top) { - set_width(r.right - r.left); - set_height(r.bottom - r.top); + set_width(std::abs(r.right - r.left)); + set_height(std::abs(r.bottom - r.top)); } Rect& Rect::operator=(const RECT& r) { origin_.SetPoint(r.left, r.top); - set_width(r.right - r.left); - set_height(r.bottom - r.top); + set_width(std::abs(r.right - r.left)); + set_height(std::abs(r.bottom - r.top)); return *this; } #elif defined(OS_MACOSX) diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc index 9cc353d..bf327ef 100644 --- a/ui/gfx/rect_unittest.cc +++ b/ui/gfx/rect_unittest.cc @@ -319,3 +319,12 @@ TEST(RectTest, SkRectToRect) { SkRect skrect = gfx::RectToSkRect(src); EXPECT_EQ(src, gfx::SkRectToRect(skrect)); } + +#if defined(OS_WIN) +TEST(RectTest, ConstructAndAssign) { + const RECT rect_1 = { 0, 0, 10, 10 }; + const RECT rect_2 = { 0, 0, -10, -10 }; + gfx::Rect test1(rect_1); + gfx::Rect test2(rect_2); +} +#endif diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc index 836d8f3..df935db 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc @@ -154,7 +154,8 @@ void NativeTabbedPaneGtk::DoAddTabAtIndex(int index, int tab_count = GetTabCount(); DCHECK(index <= tab_count); - WidgetGtk* page_container = new WidgetGtk(WidgetGtk::TYPE_CHILD); + Widget* page_container = Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); page_container->Init(NULL, gfx::Rect()); page_container->SetContentsView(contents); page_container->SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index 5176fd9..333fff0 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -17,7 +17,7 @@ #include "views/controls/tabbed_pane/tabbed_pane_listener.h" #include "views/layout/fill_layout.h" #include "views/widget/root_view.h" -#include "views/widget/widget_win.h" +#include "views/widget/widget.h" namespace views { @@ -289,7 +289,8 @@ void NativeTabbedPaneWin::CreateNativeControl() { SendMessage(tab_control, WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE); // Create the view container which is a child of the TabControl. - content_window_ = new WidgetWin(); + content_window_ = Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); content_window_->Init(tab_control, gfx::Rect()); // Explicitly setting the WS_EX_LAYOUTRTL property for the HWND (see above @@ -383,13 +384,11 @@ void NativeTabbedPaneWin::DoSelectTabAt(int index, boolean invoke_listener) { } void NativeTabbedPaneWin::ResizeContents() { - CRect content_bounds; + RECT content_bounds; if (!GetClientRect(native_view(), &content_bounds)) return; TabCtrl_AdjustRect(native_view(), FALSE, &content_bounds); - content_window_->MoveWindow(content_bounds.left, content_bounds.top, - content_bounds.Width(), content_bounds.Height(), - TRUE); + content_window_->SetBounds(gfx::Rect(content_bounds)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.h b/views/controls/tabbed_pane/native_tabbed_pane_win.h index 8eac285..6ffa867 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.h +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.h @@ -13,7 +13,7 @@ namespace views { -class WidgetWin; +class Widget; class TabLayout; class NativeTabbedPaneWin : public NativeControlWin, @@ -50,9 +50,8 @@ class NativeTabbedPaneWin : public NativeControlWin, virtual FocusTraversable* GetFocusTraversable(); virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); - virtual Widget* child_widget() { - return reinterpret_cast<Widget*>(content_window_); - } + // TODO(beng): this method should not be unix_hacker + virtual Widget* child_widget() { return content_window_; } private: // Called upon creation of native control to initialize tabs that are added @@ -86,7 +85,7 @@ class NativeTabbedPaneWin : public NativeControlWin, int selected_index_; // The window displayed in the tab. - WidgetWin* content_window_; + Widget* content_window_; DISALLOW_COPY_AND_ASSIGN(NativeTabbedPaneWin); }; diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc index 417a4b9..7e2bab4 100644 --- a/views/controls/textfield/native_textfield_views_unittest.cc +++ b/views/controls/textfield/native_textfield_views_unittest.cc @@ -78,7 +78,7 @@ class NativeTextfieldViewsTest : public ViewsTestBase, textfield_->SetController(this); Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); params.mirror_origin_in_rtl = false; - widget_ = Widget::CreatePopupWidget(params); + widget_ = Widget::CreateWidget(params); widget_->Init(NULL, gfx::Rect(100, 100, 100, 100)); View* container = new View(); widget_->SetContentsView(container); diff --git a/views/examples/widget_example.cc b/views/examples/widget_example.cc index 7b53a69..d72276c 100644 --- a/views/examples/widget_example.cc +++ b/views/examples/widget_example.cc @@ -8,10 +8,7 @@ #include "views/layout/box_layout.h" #include "views/layout/layout_manager.h" #include "views/view.h" - -#if defined(OS_LINUX) -#include "views/widget/widget_gtk.h" -#endif +#include "views/widget/widget.h" namespace { @@ -111,10 +108,9 @@ void WidgetExample::InitWidget(views::Widget* widget, bool transparent) { #if defined(OS_LINUX) void WidgetExample::CreateChild(views::View* parent, bool transparent) { - views::WidgetGtk* widget = - new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD); - if (transparent) - widget->MakeTransparent(); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); + params.transparent = transparent; + views::Widget* widget = views::Widget::CreateWidget(params); // Compute where to place the child widget. // We'll place it at the center of the root widget. views::Widget* parent_widget = parent->GetWidget(); @@ -131,7 +127,7 @@ void WidgetExample::CreateChild(views::View* parent, bool transparent) { void WidgetExample::CreatePopup(views::View* parent, bool transparent) { views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = transparent; - views::Widget* widget = views::Widget::CreatePopupWidget(params); + views::Widget* widget = views::Widget::CreateWidget(params); // Compute where to place the popup widget. // We'll place it right below the create button. diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc index 53f2527..1f54a13 100644 --- a/views/focus/focus_manager_unittest.cc +++ b/views/focus/focus_manager_unittest.cc @@ -290,18 +290,16 @@ class BorderView : public NativeViewHost { if (child == this && is_add) { if (!widget_) { + widget_ = Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); #if defined(OS_WIN) - WidgetWin* widget_win = new WidgetWin(); - widget_win->Init(parent->GetRootView()->GetWidget()->GetNativeView(), - gfx::Rect(0, 0, 0, 0)); - widget_win->SetFocusTraversableParentView(this); - widget_ = widget_win; -#else - WidgetGtk* widget_gtk = new WidgetGtk(WidgetGtk::TYPE_CHILD); - widget_gtk->Init(native_view(), gfx::Rect(0, 0, 0, 0)); - widget_gtk->SetFocusTraversableParentView(this); - widget_ = widget_gtk; + gfx::NativeView parent_native_view = + parent->GetRootView()->GetWidget()->GetNativeView(); +#elif defined(TOOLKIT_USES_GTK) + gfx::NativeView parent_native_view = native_view(); #endif + widget_->Init(parent_native_view, gfx::Rect(0, 0, 0, 0)); + widget_->SetFocusTraversableParentView(this); widget_->SetContentsView(child_); } diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 428f320..08666b5 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -54,11 +54,8 @@ class ViewTest : public ViewsTestBase { } Widget* CreateWidget() { -#if defined(OS_WIN) - return new WidgetWin(); -#elif defined(OS_LINUX) - return new WidgetGtk(WidgetGtk::TYPE_WINDOW); -#endif + return Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_WINDOW)); } }; diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 4963ce6..65382c4 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -18,10 +18,12 @@ namespace views { // Widget, CreateParams: Widget::CreateParams::CreateParams() - : type(TYPE_TOPLEVEL), + : type(TYPE_WINDOW), + child(false), transparent(false), accept_events(true), can_activate(true), + keep_on_top(false), delete_on_destroy(true), mirror_origin_in_rtl(true), has_dropshadow(false), @@ -30,9 +32,11 @@ Widget::CreateParams::CreateParams() Widget::CreateParams::CreateParams(Type type) : type(type), + child(type == TYPE_CONTROL), transparent(false), accept_events(true), can_activate(type != TYPE_POPUP && type != TYPE_MENU), + keep_on_top(type == TYPE_MENU), delete_on_destroy(true), mirror_origin_in_rtl(true), has_dropshadow(false), diff --git a/views/widget/widget.h b/views/widget/widget.h index 71f33bf..b0e22a3 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -62,10 +62,11 @@ class Widget : public internal::NativeWidgetDelegate, public: struct CreateParams { enum Type { - TYPE_TOPLEVEL, - TYPE_CHILD, - TYPE_POPUP, - TYPE_MENU + TYPE_WINDOW, // A Window, like a frame window. + TYPE_CONTROL, // A control, like a button. + TYPE_POPUP, // An undecorated Window, with transient properties. + TYPE_MENU // An undecorated Window, with transient properties + // specialized to menus. }; CreateParams(); @@ -73,9 +74,11 @@ class Widget : public internal::NativeWidgetDelegate, Type type; + bool child; bool transparent; bool accept_events; bool can_activate; + bool keep_on_top; bool delete_on_destroy; bool mirror_origin_in_rtl; bool has_dropshadow; @@ -85,8 +88,8 @@ class Widget : public internal::NativeWidgetDelegate, Widget(); virtual ~Widget(); - // Creates a Widget instance suitable for use as a transient popup. - static Widget* CreatePopupWidget(const CreateParams& params); + // Creates a Widget instance with the supplied params. + static Widget* CreateWidget(const CreateParams& params); // Enumerates all windows pertaining to us and notifies their // view hierarchies that the locale has changed. diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index b2371f8..a3f16d3 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -1547,10 +1547,30 @@ void WidgetGtk::DrawTransparentBackground(GtkWidget* widget, // Widget, public: // static -Widget* Widget::CreatePopupWidget(const CreateParams& params) { - WidgetGtk* popup = new WidgetGtk(WidgetGtk::TYPE_POPUP); - popup->SetCreateParams(params); - return popup; +Widget* Widget::CreateWidget(const CreateParams& params) { + // TODO(beng): coalesce with CreateParams::Type. + WidgetGtk::Type widget_gtk_type; + switch (params.type) { + case CreateParams::TYPE_CONTROL: + widget_gtk_type = WidgetGtk::TYPE_CHILD; + break; + case CreateParams::TYPE_MENU: + widget_gtk_type = WidgetGtk::TYPE_POPUP; + break; + case CreateParams::TYPE_POPUP: + widget_gtk_type = WidgetGtk::TYPE_POPUP; + break; + case CreateParams::TYPE_WINDOW: + widget_gtk_type = WidgetGtk::TYPE_DECORATED_WINDOW; + break; + default: + NOTREACHED(); + break; + } + + WidgetGtk* widget = new WidgetGtk(widget_gtk_type); + widget->SetCreateParams(params); + return widget; } // static diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 147c443..ebf3129 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -162,10 +162,14 @@ void WidgetWin::SetCreateParams(const CreateParams& params) { DWORD class_style = CS_DBLCLKS; // Set type-independent style attributes. + if (params.child) + style |= WS_CHILD; if (!params.accept_events) ex_style |= WS_EX_TRANSPARENT; if (!params.can_activate) ex_style |= WS_EX_NOACTIVATE; + if (params.keep_on_top) + ex_style |= WS_EX_TOPMOST; if (params.mirror_origin_in_rtl) ex_style |= l10n_util::GetExtendedTooltipStyles(); if (params.transparent) @@ -177,10 +181,8 @@ void WidgetWin::SetCreateParams(const CreateParams& params) { // Set type-dependent style attributes. switch (params.type) { - case CreateParams::TYPE_TOPLEVEL: - break; - case CreateParams::TYPE_CHILD: - style |= WS_CHILD; + case CreateParams::TYPE_WINDOW: + case CreateParams::TYPE_CONTROL: break; case CreateParams::TYPE_POPUP: style |= WS_POPUP; @@ -188,7 +190,6 @@ void WidgetWin::SetCreateParams(const CreateParams& params) { break; case CreateParams::TYPE_MENU: style |= WS_POPUP; - ex_style |= WS_EX_TOPMOST; is_mouse_down_ = ((GetKeyState(VK_LBUTTON) & 0x80) || (GetKeyState(VK_RBUTTON) & 0x80) || @@ -1201,10 +1202,10 @@ gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() { // Widget, public: // static -Widget* Widget::CreatePopupWidget(const CreateParams& params) { - WidgetWin* popup = new WidgetWin; - popup->SetCreateParams(params); - return popup; +Widget* Widget::CreateWidget(const CreateParams& params) { + WidgetWin* widget = new WidgetWin; + widget->SetCreateParams(params); + return widget; } // static |