diff options
70 files changed, 680 insertions, 737 deletions
diff --git a/chrome/browser/chromeos/frame/panel_controller.cc b/chrome/browser/chromeos/frame/panel_controller.cc index 6294f2e..cff8723 100644 --- a/chrome/browser/chromeos/frame/panel_controller.cc +++ b/chrome/browser/chromeos/frame/panel_controller.cc @@ -141,10 +141,11 @@ void PanelController::Init(bool initial_focus, WmIpcPanelUserResizeType resize_type) { gfx::Rect title_bounds(0, 0, window_bounds.width(), kTitleHeight); + title_window_ = views::Widget::CreateWidget(); views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); params.transparent = true; - title_window_ = views::Widget::CreateWidget(params); - title_window_->Init(NULL, title_bounds); + params.bounds = title_bounds; + title_window_->Init(params); gtk_widget_set_size_request(title_window_->GetNativeView(), title_bounds.width(), title_bounds.height()); title_ = title_window_->GetNativeView(); diff --git a/chrome/browser/chromeos/input_method/candidate_window.cc b/chrome/browser/chromeos/input_method/candidate_window.cc index 9199ecc..dc693ca 100644 --- a/chrome/browser/chromeos/input_method/candidate_window.cc +++ b/chrome/browser/chromeos/input_method/candidate_window.cc @@ -1282,10 +1282,10 @@ bool CandidateWindowController::Impl::Init() { void CandidateWindowController::Impl::CreateView() { // Create a non-decorated frame. - frame_.reset(views::Widget::CreateWidget( - views::Widget::CreateParams(views::Widget::CreateParams::TYPE_POPUP))); + frame_.reset(views::Widget::CreateWidget()); // The size is initially zero. - frame_->Init(NULL, gfx::Rect(0, 0)); + frame_->Init( + views::Widget::CreateParams(views::Widget::CreateParams::TYPE_POPUP)); // Create the candidate window. candidate_window_ = new CandidateWindowView(frame_.get()); diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc index cd7bc58..17a5714 100644 --- a/chrome/browser/chromeos/login/background_view.cc +++ b/chrome/browser/chromeos/login/background_view.cc @@ -169,9 +169,10 @@ views::Widget* BackgroundView::CreateWindowContainingView( BackgroundView** view) { ResetXCursor(); - Widget* window = Widget::CreateWidget( - Widget::CreateParams(Widget::CreateParams::TYPE_WINDOW)); - window->Init(NULL, bounds); + Widget* window = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.bounds = bounds; + window->Init(params); *view = new BackgroundView(); (*view)->Init(background_url); diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc index 3dd8b01..f9e7919 100644 --- a/chrome/browser/chromeos/login/helper.cc +++ b/chrome/browser/chromeos/login/helper.cc @@ -109,13 +109,16 @@ void ThrobberHostView::StartThrobber() { throbber->set_stop_delay_ms(0); gfx::Rect throbber_bounds = CalculateThrobberBounds(throbber); - 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_ = views::Widget::CreateWidget(); + static_cast<views::WidgetGtk*>(throbber_widget_->native_widget())-> + make_transient_to_parent(); throbber_bounds.Offset(host_view_->GetScreenBounds().origin()); - throbber_widget_->Init(host_gtk_window, throbber_bounds); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); + params.transparent = true; + params.bounds = throbber_bounds; + params.parent = host_gtk_window; + throbber_widget_->Init(params); throbber_widget_->SetContentsView(throbber); // This keeps the window from flashing at startup. gdk_window_set_back_pixmap( diff --git a/chrome/browser/chromeos/login/message_bubble.cc b/chrome/browser/chromeos/login/message_bubble.cc index e7a099c..25ebd7b 100644 --- a/chrome/browser/chromeos/login/message_bubble.cc +++ b/chrome/browser/chromeos/login/message_bubble.cc @@ -21,7 +21,7 @@ namespace chromeos { static const int kBorderSize = 4; static const int kMaxLabelWidth = 250; -MessageBubble::MessageBubble(views::WidgetGtk::Type type, +MessageBubble::MessageBubble(views::Widget::CreateParams::Type type, views::Widget* parent, SkBitmap* image, const std::wstring& text, @@ -114,7 +114,8 @@ MessageBubble* MessageBubble::Show(views::Widget* parent, MessageBubbleDelegate* delegate) { // The bubble will be destroyed when it is closed. MessageBubble* bubble = new MessageBubble( - views::WidgetGtk::TYPE_WINDOW, parent, image, text, help, true, delegate); + views::Widget::CreateParams::TYPE_WINDOW, parent, image, text, help, + true, delegate); bubble->InitBubble(parent, position_relative_to, arrow_location, bubble->text_->parent(), delegate); return bubble; @@ -131,7 +132,8 @@ MessageBubble* MessageBubble::ShowNoGrab( MessageBubbleDelegate* delegate) { // The bubble will be destroyed when it is closed. MessageBubble* bubble = new MessageBubble( - views::WidgetGtk::TYPE_CHILD, parent, image, text, help, false, delegate); + views::Widget::CreateParams::TYPE_CONTROL, parent, image, text, help, + false, delegate); bubble->InitBubble(parent, position_relative_to, arrow_location, bubble->text_->parent(), delegate); return bubble; diff --git a/chrome/browser/chromeos/login/message_bubble.h b/chrome/browser/chromeos/login/message_bubble.h index 0b22697..d734c70 100644 --- a/chrome/browser/chromeos/login/message_bubble.h +++ b/chrome/browser/chromeos/login/message_bubble.h @@ -77,7 +77,7 @@ class MessageBubble : public Bubble, virtual void SetMouseCapture(); private: - MessageBubble(views::WidgetGtk::Type type, + MessageBubble(views::Widget::CreateParams::Type type, views::Widget* parent, SkBitmap* image, const std::wstring& text, diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index 2e79b6f..195d50a 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -198,9 +198,7 @@ static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer( // focus/events inside the grab widget. class LockWindow : public views::WidgetGtk { public: - LockWindow() - : views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW), - toplevel_focus_widget_(NULL) { + LockWindow() : toplevel_focus_widget_(NULL) { EnableDoubleBuffer(true); } @@ -284,8 +282,7 @@ class GrabWidgetRootView class GrabWidget : public views::WidgetGtk { public: explicit GrabWidget(chromeos::ScreenLocker* screen_locker) - : views::WidgetGtk(views::WidgetGtk::TYPE_CHILD), - screen_locker_(screen_locker), + : screen_locker_(screen_locker), ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), grab_failure_count_(0), kbd_grab_status_(GDK_GRAB_INVALID_TIME), @@ -478,7 +475,7 @@ class ScreenLockerBackgroundView : public chromeos::BackgroundView, public chromeos::ScreenLocker::ScreenLockViewContainer { public: - ScreenLockerBackgroundView(views::WidgetGtk* lock_widget, + ScreenLockerBackgroundView(views::Widget* lock_widget, views::View* screen_lock_view) : lock_widget_(lock_widget), screen_lock_view_(screen_lock_view) { @@ -511,7 +508,7 @@ class ScreenLockerBackgroundView } private: - views::WidgetGtk* lock_widget_; + views::Widget* lock_widget_; views::View* screen_lock_view_; @@ -688,7 +685,9 @@ void ScreenLocker::Init() { LockWindow* lock_window = new LockWindow(); lock_window_ = lock_window; - lock_window_->Init(NULL, init_bounds); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); + params.bounds = init_bounds; + lock_window_->Init(params); g_signal_connect(lock_window_->GetNativeView(), "client-event", G_CALLBACK(OnClientEventThunk), this); @@ -710,8 +709,11 @@ void ScreenLocker::Init() { // namespace feels a bit ugly.) GrabWidget* cast_lock_widget = new GrabWidget(this); lock_widget_ = cast_lock_widget; - lock_widget_->MakeTransparent(); - lock_widget_->InitWithWidget(lock_window_, gfx::Rect()); + views::Widget::CreateParams lock_params( + views::Widget::CreateParams::TYPE_CONTROL); + lock_params.transparent = true; + lock_params.parent_widget = lock_window_; + lock_widget_->Init(lock_params); if (screen_lock_view_) { GrabWidgetRootView* root_view = new GrabWidgetRootView(screen_lock_view_); grab_container_ = root_view; @@ -762,7 +764,9 @@ void ScreenLocker::Init() { NULL, false); gdk_window_set_back_pixmap(lock_widget_->GetNativeView()->window, NULL, false); - lock_window->set_toplevel_focus_widget(lock_widget_->window_contents()); + lock_window->set_toplevel_focus_widget( + static_cast<views::WidgetGtk*>(lock_widget_->native_widget())-> + window_contents()); // Create the SystemKeyEventListener so it can listen for system keyboard // messages regardless of focus while screen locked. diff --git a/chrome/browser/chromeos/login/screen_locker.h b/chrome/browser/chromeos/login/screen_locker.h index 9ef42d0..23d2afc 100644 --- a/chrome/browser/chromeos/login/screen_locker.h +++ b/chrome/browser/chromeos/login/screen_locker.h @@ -168,10 +168,10 @@ class ScreenLocker : public LoginStatusConsumer, CHROMEGTK_CALLBACK_1(ScreenLocker, void, OnClientEvent, GdkEventClient*); // The screen locker window. - views::WidgetGtk* lock_window_; + views::Widget* lock_window_; - // TYPE_CHILD widget to grab the keyboard/mouse input. - views::WidgetGtk* lock_widget_; + // Child widget to grab the keyboard/mouse input. + views::Widget* lock_widget_; // A view that accepts password. ScreenLockView* screen_lock_view_; diff --git a/chrome/browser/chromeos/login/user_controller.cc b/chrome/browser/chromeos/login/user_controller.cc index ef97ebd0..208321f 100644 --- a/chrome/browser/chromeos/login/user_controller.cc +++ b/chrome/browser/chromeos/login/user_controller.cc @@ -419,10 +419,11 @@ void UserController::CreateBorderWindow(int index, height += 2 * kBorderSize + kUserImageSize + kVerticalIntervalSize; } + border_window_ = Widget::CreateWidget(); 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)); + params.bounds = gfx::Rect(0, 0, width, height); + border_window_->Init(params); if (!is_new_user_) { views::View* background_view = new views::View(); views::Painter* painter = CreateWizardPainter( diff --git a/chrome/browser/chromeos/login/user_controller_gtk.cc b/chrome/browser/chromeos/login/user_controller_gtk.cc index 2b7717e..bcd5023 100644 --- a/chrome/browser/chromeos/login/user_controller_gtk.cc +++ b/chrome/browser/chromeos/login/user_controller_gtk.cc @@ -14,7 +14,7 @@ namespace { class ControlsWidget : public WidgetGtk { public: - ControlsWidget() : WidgetGtk(WidgetGtk::TYPE_WINDOW) { + ControlsWidget() { } private: @@ -38,8 +38,7 @@ class ControlsWidget : public WidgetGtk { class ClickNotifyingWidget : public WidgetGtk { public: explicit ClickNotifyingWidget(UserController* controller) - : WidgetGtk(WidgetGtk::TYPE_WINDOW), - controller_(controller) { + : controller_(controller) { } private: @@ -55,9 +54,11 @@ class ClickNotifyingWidget : public WidgetGtk { DISALLOW_COPY_AND_ASSIGN(ClickNotifyingWidget); }; -WidgetGtk* InitWidget(WidgetGtk* widget, const gfx::Rect& bounds) { - widget->MakeTransparent(); - widget->Init(NULL, bounds); +views::Widget* InitWidget(views::Widget* widget, const gfx::Rect& bounds) { + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); + params.transparent = true; + params.bounds = bounds; + widget->Init(params); GdkWindow* gdk_window = widget->GetNativeView()->window; gdk_window_set_back_pixmap(gdk_window, NULL, false); return widget; diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index 0d8c162..258908b 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -596,18 +596,19 @@ void WizardController::InitiateOOBEUpdate() { views::Widget* WizardController::CreateScreenWindow( const gfx::Rect& bounds, bool initial_show) { - views::Widget::CreateParams widget_params( - views::Widget::CreateParams::TYPE_WINDOW); - widget_params.transparent = true; - widget_ = views::Widget::CreateWidget(widget_params); + widget_ = views::Widget::CreateWidget(); // Window transparency makes background flicker through controls that // are constantly updating its contents (like image view with video // stream). Hence enabling double buffer. static_cast<views::WidgetGtk*>(widget_)->EnableDoubleBuffer(true); - widget_->Init(NULL, bounds); + views::Widget::CreateParams widget_params( + views::Widget::CreateParams::TYPE_WINDOW); + widget_params.transparent = true; + widget_params.bounds = bounds; + widget_->Init(widget_params); std::vector<int> params; // For initial show WM would animate background window. - // Otherwise it stays unchaged. + // Otherwise it stays unchanged. params.push_back(initial_show); chromeos::WmIpc::instance()->SetWindowType( widget_->GetNativeView(), diff --git a/chrome/browser/chromeos/notifications/balloon_view.cc b/chrome/browser/chromeos/notifications/balloon_view.cc index 6246e51..89317af 100644 --- a/chrome/browser/chromeos/notifications/balloon_view.cc +++ b/chrome/browser/chromeos/notifications/balloon_view.cc @@ -267,19 +267,19 @@ 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(views::Widget::CreateWidget()); + static_cast<views::WidgetGtk*>(control_view_host_.get())-> + 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()); + params.parent = GetParentNativeView(); + control_view_host_->Init(params); NotificationControlView* control = new NotificationControlView(this); control_view_host_->SetContentsView(control); } - if (!is_add && this == child && control_view_host_.get() && controls_) { + if (!is_add && this == child && control_view_host_.get() && controls_) control_view_host_.release()->CloseNow(); - } } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/chromeos/notifications/notification_panel.cc b/chrome/browser/chromeos/notifications/notification_panel.cc index c6b311c..1724b56 100644 --- a/chrome/browser/chromeos/notifications/notification_panel.cc +++ b/chrome/browser/chromeos/notifications/notification_panel.cc @@ -73,8 +73,7 @@ chromeos::BalloonViewImpl* GetBalloonViewOf(const Balloon* balloon) { class ViewportWidget : public views::WidgetGtk { public: explicit ViewportWidget(chromeos::NotificationPanel* panel) - : WidgetGtk(views::WidgetGtk::TYPE_CHILD), - panel_(panel) { + : panel_(panel) { } void UpdateControl() { @@ -415,18 +414,18 @@ NotificationPanel::~NotificationPanel() { void NotificationPanel::Show() { if (!panel_widget_) { - // TODO(oshima): Using window because Popup widget behaves weird - // when resizing. This needs to be investigated. - views::WidgetGtk* widget_gtk = - new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW); + panel_widget_ = views::Widget::CreateWidget(); // Enable double buffering because the panel has both pure views // control and native controls (scroll bar). - widget_gtk->EnableDoubleBuffer(true); - panel_widget_ = widget_gtk; + static_cast<views::WidgetGtk*>(panel_widget_->native_widget())-> + EnableDoubleBuffer(true); gfx::Rect bounds = GetPreferredBounds(); bounds = bounds.Union(min_bounds_); - panel_widget_->Init(NULL, bounds); + views::Widget::CreateParams params( + views::Widget::CreateParams::TYPE_WINDOW); + params.bounds = bounds; + panel_widget_->Init(params); // Set minimum bounds so that it can grow freely. gtk_widget_set_size_request(GTK_WIDGET(panel_widget_->GetNativeView()), min_bounds_.width(), min_bounds_.height()); @@ -439,7 +438,8 @@ void NotificationPanel::Show() { // Add the view port after scroll_view is attached to the panel widget. ViewportWidget* widget = new ViewportWidget(this); container_host_ = widget; - container_host_->Init(NULL, gfx::Rect()); + container_host_->Init( + views::Widget::CreateParams(views::Widget::CreateParams::TYPE_CONTROL)); container_host_->SetContentsView(balloon_container_.get()); // The window_contents_ is onwed by the WidgetGtk. Increase ref count // so that window_contents does not get deleted when detached. diff --git a/chrome/browser/chromeos/panels/panel_scroller.cc b/chrome/browser/chromeos/panels/panel_scroller.cc index 70e72e9..9572a19 100644 --- a/chrome/browser/chromeos/panels/panel_scroller.cc +++ b/chrome/browser/chromeos/panels/panel_scroller.cc @@ -80,9 +80,10 @@ PanelScroller::~PanelScroller() { // static PanelScroller* PanelScroller::CreateWindow() { - views::Widget* widget = views::Widget::CreateWidget( - views::Widget::CreateParams(views::Widget::CreateParams::TYPE_WINDOW)); - widget->Init(NULL, gfx::Rect(0, 0, 100, 800)); + views::Widget* widget = views::Widget::CreateWidget(); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); + params.bounds = gfx::Rect(0, 0, 100, 800); + widget->Init(params); PanelScroller* scroller = new PanelScroller(); widget->SetContentsView(scroller); diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index 5c7ec31..6e86bb5 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -134,7 +134,10 @@ bool ExternalTabContainer::Init(Profile* profile, route_all_top_level_navigations_ = route_all_top_level_navigations; set_window_style(WS_POPUP | WS_CLIPCHILDREN); - views::WidgetWin::Init(NULL, bounds); + + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.bounds = bounds; + GetWidget()->Init(params); if (!IsWindow()) { NOTREACHED(); return false; diff --git a/chrome/browser/first_run/try_chrome_dialog_view.cc b/chrome/browser/first_run/try_chrome_dialog_view.cc index d9b3d88..47c9996 100644 --- a/chrome/browser/first_run/try_chrome_dialog_view.cc +++ b/chrome/browser/first_run/try_chrome_dialog_view.cc @@ -65,16 +65,16 @@ TryChromeDialogView::Result TryChromeDialogView::ShowModal( gfx::Size icon_size = icon->GetPreferredSize(); // An approximate window size. After Layout() we'll get better bounds. - views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); - params.can_activate = true; - popup_ = views::Widget::CreateWidget(params); + popup_ = views::Widget::CreateWidget(); if (!popup_) { NOTREACHED(); return DIALOG_ERROR; } - gfx::Rect pos(310, 160); - popup_->Init(NULL, pos); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.can_activate = true; + params.bounds = gfx::Rect(310, 160); + popup_->Init(params); views::RootView* root_view = popup_->GetRootView(); // The window color is a tiny bit off-white. @@ -194,8 +194,8 @@ TryChromeDialogView::Result TryChromeDialogView::ShowModal( // account the differences between XP and Vista fonts and buttons. layout->Layout(root_view); gfx::Size preferred = layout->GetPreferredSize(root_view); - pos = ComputeWindowPosition(preferred.width(), preferred.height(), - base::i18n::IsRTL()); + gfx::Rect pos = ComputeWindowPosition(preferred.width(), preferred.height(), + base::i18n::IsRTL()); popup_->SetBounds(pos); // Carve the toast shape into the window. diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc index 0648704..0529dad 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc @@ -332,8 +332,9 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() { views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.can_activate = false; params.transparent = true; - popup_->SetCreateParams(params); - popup_->Init(location_bar_->GetWidget()->GetNativeView(), GetPopupBounds()); + params.parent = location_bar_->GetWidget()->GetNativeView(); + params.bounds = GetPopupBounds(); + popup_->GetWidget()->Init(params); popup_->SetContentsView(this); popup_->MoveAbove(popup_->GetRelativeWindowForPopup( edit_view_->GetNativeView())); diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.cc index 9796e77..d0299a8 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.cc @@ -9,8 +9,7 @@ //////////////////////////////////////////////////////////////////////////////// // AutocompletePopupGtk, public: -AutocompletePopupGtk::AutocompletePopupGtk() - : WidgetGtk(WidgetGtk::TYPE_POPUP) { +AutocompletePopupGtk::AutocompletePopupGtk() { } AutocompletePopupGtk::~AutocompletePopupGtk() { diff --git a/chrome/browser/ui/views/browser_bubble_gtk.cc b/chrome/browser/ui/views/browser_bubble_gtk.cc index 8195220..fdf2654 100644 --- a/chrome/browser/ui/views/browser_bubble_gtk.cc +++ b/chrome/browser/ui/views/browser_bubble_gtk.cc @@ -23,8 +23,7 @@ namespace { class BubbleWidget : public views::WidgetGtk { public: explicit BubbleWidget(BrowserBubble* bubble) - : views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW), - bubble_(bubble), + : bubble_(bubble), border_contents_(new BorderContents) { border_contents_->Init(); } @@ -95,7 +94,9 @@ void BrowserBubble::InitPopup() { BubbleWidget* pop = new BubbleWidget(this); pop->MakeTransparent(); pop->make_transient_to_parent(); - pop->Init(frame_->GetNativeView(), gfx::Rect()); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_WINDOW); + params.parent = frame_->GetNativeView(); + pop->Init(params); #if defined(OS_CHROMEOS) { vector<int> params; diff --git a/chrome/browser/ui/views/browser_bubble_win.cc b/chrome/browser/ui/views/browser_bubble_win.cc index 8392bd381..16b4266 100644 --- a/chrome/browser/ui/views/browser_bubble_win.cc +++ b/chrome/browser/ui/views/browser_bubble_win.cc @@ -109,16 +109,19 @@ void BrowserBubble::InitPopup() { // popup_ is a Widget, but we need to do some WidgetWin stuff first, then // we'll assign it into popup_. BubbleWidget* pop = new BubbleWidget(this); + popup_ = pop; BorderWidgetWin* border_widget = pop->border_widget(); - border_widget->Init(new BorderContents, frame_->GetNativeView()); + border_widget->InitBorderWidgetWin(new BorderContents, + frame_->GetNativeView()); // We make the BorderWidgetWin the owner of the Bubble HWND, so that the // latter is displayed on top of the former. - pop->Init(border_widget->GetNativeView(), gfx::Rect()); - pop->SetContentsView(view_); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.parent = border_widget->GetNativeView(); + popup_->Init(params); + popup_->SetContentsView(view_); - popup_ = pop; ResizeToView(); Reposition(); diff --git a/chrome/browser/ui/views/bubble/border_widget_win.cc b/chrome/browser/ui/views/bubble/border_widget_win.cc index 0c71bee..e43558d 100644 --- a/chrome/browser/ui/views/bubble/border_widget_win.cc +++ b/chrome/browser/ui/views/bubble/border_widget_win.cc @@ -10,15 +10,18 @@ BorderWidgetWin::BorderWidgetWin() : border_contents_(NULL) { - set_window_style(WS_POPUP); - set_window_ex_style(WS_EX_TOOLWINDOW | WS_EX_LAYERED); } -void BorderWidgetWin::Init(BorderContents* border_contents, HWND owner) { +void BorderWidgetWin::InitBorderWidgetWin(BorderContents* border_contents, + HWND owner) { DCHECK(!border_contents_); border_contents_ = border_contents; border_contents_->Init(); - WidgetWin::Init(owner, gfx::Rect()); + + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.transparent = true; + params.parent = owner; + GetWidget()->Init(params); SetContentsView(border_contents_); SetWindowPos(owner, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOREDRAW); diff --git a/chrome/browser/ui/views/bubble/border_widget_win.h b/chrome/browser/ui/views/bubble/border_widget_win.h index e087163..a6f9256 100644 --- a/chrome/browser/ui/views/bubble/border_widget_win.h +++ b/chrome/browser/ui/views/bubble/border_widget_win.h @@ -22,7 +22,7 @@ class BorderWidgetWin : public views::WidgetWin { virtual ~BorderWidgetWin() { } // Initializes the BrowserWidget making |owner| its owning window. - void Init(BorderContents* border_contents, HWND owner); + void InitBorderWidgetWin(BorderContents* border_contents, HWND owner); // Given the size of the contained contents (without margins), and the rect // (in screen coordinates) to point to, sets the border window positions and diff --git a/chrome/browser/ui/views/bubble/bubble.cc b/chrome/browser/ui/views/bubble/bubble.cc index 49b8d59..29ea30a 100644 --- a/chrome/browser/ui/views/bubble/bubble.cc +++ b/chrome/browser/ui/views/bubble/bubble.cc @@ -69,7 +69,7 @@ Bubble* Bubble::ShowFocusless( views::View* contents, BubbleDelegate* delegate, bool show_while_screen_is_locked) { - Bubble* bubble = new Bubble(views::WidgetGtk::TYPE_POPUP, + Bubble* bubble = new Bubble(views::Widget::CreateParams::TYPE_POPUP, show_while_screen_is_locked); bubble->InitBubble(parent, position_relative_to, arrow_location, contents, delegate); @@ -122,7 +122,6 @@ void Bubble::AnimationProgressed(const ui::Animation* animation) { Bubble::Bubble() : #if defined(OS_LINUX) - WidgetGtk(TYPE_WINDOW), border_contents_(NULL), #elif defined(OS_WIN) border_(NULL), @@ -131,6 +130,7 @@ Bubble::Bubble() show_status_(kOpen), fade_away_on_close_(false), #if defined(OS_CHROMEOS) + type_(views::Widget::CreateParams::TYPE_WINDOW), show_while_screen_is_locked_(false), #endif arrow_location_(BubbleBorder::NONE), @@ -138,12 +138,13 @@ Bubble::Bubble() } #if defined(OS_CHROMEOS) -Bubble::Bubble(views::WidgetGtk::Type type, bool show_while_screen_is_locked) - : WidgetGtk(type), - border_contents_(NULL), +Bubble::Bubble(views::Widget::CreateParams::Type type, + bool show_while_screen_is_locked) + : border_contents_(NULL), delegate_(NULL), show_status_(kOpen), fade_away_on_close_(false), + type_(type), show_while_screen_is_locked_(show_while_screen_is_locked), arrow_location_(BubbleBorder::NONE), contents_(NULL) { @@ -185,18 +186,21 @@ void Bubble::InitBubble(views::Widget* parent, SetOpacity(0); } - border_->Init(CreateBorderContents(), parent->GetNativeView()); + border_->InitBorderWidgetWin(CreateBorderContents(), parent->GetNativeView()); border_->border_contents()->SetBackgroundColor(kBackgroundColor); // We make the BorderWidgetWin the owner of the Bubble HWND, so that the // latter is displayed on top of the former. - WidgetWin::Init(border_->GetNativeView(), gfx::Rect()); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.parent = border_->GetNativeView(); + GetWidget()->Init(params); SetWindowText(GetNativeView(), delegate_->accessible_name().c_str()); #elif defined(OS_LINUX) - MakeTransparent(); - make_transient_to_parent(); - WidgetGtk::InitWithWidget(parent, gfx::Rect()); + views::Widget::CreateParams params(type_); + params.transparent = true; + params.parent_widget = parent; + GetWidget()->Init(params); #if defined(OS_CHROMEOS) { vector<int> params; diff --git a/chrome/browser/ui/views/bubble/bubble.h b/chrome/browser/ui/views/bubble/bubble.h index 4c4f59c..3504ab9 100644 --- a/chrome/browser/ui/views/bubble/bubble.h +++ b/chrome/browser/ui/views/bubble/bubble.h @@ -135,7 +135,8 @@ class Bubble protected: Bubble(); #if defined(OS_CHROMEOS) - Bubble(views::WidgetGtk::Type type, bool show_while_screen_is_locked); + Bubble(views::Widget::CreateParams::Type type, + bool show_while_screen_is_locked); #endif virtual ~Bubble(); @@ -201,6 +202,8 @@ class Bubble bool fade_away_on_close_; #if defined(OS_CHROMEOS) + // Some callers want the bubble to be a child control instead of a window. + views::Widget::CreateParams::Type type_; // Should we set a property telling the window manager to show this window // onscreen even when the screen is locked? bool show_while_screen_is_locked_; diff --git a/chrome/browser/ui/views/constrained_html_delegate_gtk.cc b/chrome/browser/ui/views/constrained_html_delegate_gtk.cc index ea48190..1b3855b 100644 --- a/chrome/browser/ui/views/constrained_html_delegate_gtk.cc +++ b/chrome/browser/ui/views/constrained_html_delegate_gtk.cc @@ -69,8 +69,7 @@ class ConstrainedHtmlDelegateGtk : public views::WidgetGtk, ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( Profile* profile, HtmlDialogUIDelegate* delegate) - : views::WidgetGtk(views::WidgetGtk::TYPE_CHILD), - HtmlDialogTabContentsDelegate(profile), + : HtmlDialogTabContentsDelegate(profile), html_tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL), tab_container_(NULL), html_delegate_(delegate), @@ -85,7 +84,8 @@ ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( GURL(), PageTransition::START_PAGE); - Init(NULL, gfx::Rect()); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); + GetWidget()->Init(params); tab_container_ = new TabContentsContainer; SetContentsView(tab_container_); diff --git a/chrome/browser/ui/views/dom_view_browsertest.cc b/chrome/browser/ui/views/dom_view_browsertest.cc index bd5dc14..2d5c3b9 100644 --- a/chrome/browser/ui/views/dom_view_browsertest.cc +++ b/chrome/browser/ui/views/dom_view_browsertest.cc @@ -14,10 +14,10 @@ using namespace views; class DOMViewTest : public InProcessBrowserTest { public: Widget* CreatePopupWindow() { + Widget* widget = Widget::CreateWidget(); Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); - params.mirror_origin_in_rtl = false; - Widget* widget = Widget::CreateWidget(params); - widget->Init(NULL, gfx::Rect(0, 0, 400, 400)); + params.bounds = gfx::Rect(0, 0, 400, 400); + widget->Init(params); return widget; } }; diff --git a/chrome/browser/ui/views/download/download_started_animation_win.cc b/chrome/browser/ui/views/download/download_started_animation_win.cc index 602f8e7..e5a193b 100644 --- a/chrome/browser/ui/views/download/download_started_animation_win.cc +++ b/chrome/browser/ui/views/download/download_started_animation_win.cc @@ -101,13 +101,14 @@ DownloadStartedAnimationWin::DownloadStartedAnimationWin( SetImage(kDownloadImage); - gfx::Rect rc(0, 0, 0, 0); + popup_ = views::Widget::CreateWidget(); + popup_->SetOpacity(0x00); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; - popup_ = views::Widget::CreateWidget(params); - popup_->SetOpacity(0x00); - popup_->Init(tab_contents_->GetNativeView(), rc); + params.parent = tab_contents_->GetNativeView(); + popup_->Init(params); popup_->SetContentsView(this); Reposition(); popup_->Show(); diff --git a/chrome/browser/ui/views/dropdown_bar_host.cc b/chrome/browser/ui/views/dropdown_bar_host.cc index a5ea1c7..d65ebda 100644 --- a/chrome/browser/ui/views/dropdown_bar_host.cc +++ b/chrome/browser/ui/views/dropdown_bar_host.cc @@ -54,8 +54,11 @@ void DropdownBarHost::Init(DropdownBarView* view) { view_ = view; // Initialize the host. - host_.reset(CreateHost()); - host_->InitWithWidget(browser_view_->GetWidget(), gfx::Rect()); + host_.reset(views::Widget::CreateWidget()); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); + params.delete_on_destroy = false; + params.parent_widget = browser_view_->GetWidget(); + host_->Init(params); host_->SetContentsView(view_); // Start listening to focus changes, so we can register and unregister our diff --git a/chrome/browser/ui/views/dropdown_bar_host.h b/chrome/browser/ui/views/dropdown_bar_host.h index 27628c0..c53f40c 100644 --- a/chrome/browser/ui/views/dropdown_bar_host.h +++ b/chrome/browser/ui/views/dropdown_bar_host.h @@ -136,9 +136,6 @@ class DropdownBarHost : public views::AcceleratorTarget, // truncated to prevent from drawing onto Chrome's window border. void UpdateWindowEdges(const gfx::Rect& new_pos); - // Creates and returns the native Widget. - views::Widget* CreateHost(); - // Allows implementation to tweak widget position. void SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw); diff --git a/chrome/browser/ui/views/dropdown_bar_host_gtk.cc b/chrome/browser/ui/views/dropdown_bar_host_gtk.cc index a954f5d..32f6c99 100644 --- a/chrome/browser/ui/views/dropdown_bar_host_gtk.cc +++ b/chrome/browser/ui/views/dropdown_bar_host_gtk.cc @@ -15,13 +15,6 @@ #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" #endif -views::Widget* DropdownBarHost::CreateHost() { - views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); - // We own the host. - params.delete_on_destroy = false; - return views::Widget::CreateWidget(params); -} - void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw) { host_->SetBounds(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 33e8a60..74190fd 100644 --- a/chrome/browser/ui/views/dropdown_bar_host_win.cc +++ b/chrome/browser/ui/views/dropdown_bar_host_win.cc @@ -22,16 +22,6 @@ NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent( return NativeWebKeyboardEvent(hwnd, key_event.native_event().message, key, 0); } -views::Widget* DropdownBarHost::CreateHost() { - views::WidgetWin* widget = new views::WidgetWin(); - 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; - widget->SetCreateParams(params); - return widget; -} - void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw) { gfx::Rect window_rect = host_->GetWindowScreenBounds(); diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 5b0e94b..a3e93da 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -60,7 +60,7 @@ BrowserFrameWin::~BrowserFrameWin() { } void BrowserFrameWin::InitBrowserFrame() { - WindowWin::Init(NULL, gfx::Rect()); + GetWidget()->Init(views::Widget::WindowCreateParams()); } // static diff --git a/chrome/browser/ui/views/frame/contents_container.cc b/chrome/browser/ui/views/frame/contents_container.cc index 3bd97a1..ebe4cb3 100644 --- a/chrome/browser/ui/views/frame/contents_container.cc +++ b/chrome/browser/ui/views/frame/contents_container.cc @@ -152,15 +152,17 @@ void ContentsContainer::Layout() { void ContentsContainer::CreateOverlay(int initial_opacity) { DCHECK(!active_overlay_); - views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); - params.transparent = true; - params.accept_events = false; - active_overlay_ = views::Widget::CreateWidget(params); + active_overlay_ = views::Widget::CreateWidget(); active_overlay_->SetOpacity(initial_opacity); gfx::Point screen_origin; views::View::ConvertPointToScreen(active_, &screen_origin); gfx::Rect overlay_bounds(screen_origin, active_->size()); - active_overlay_->Init(active_->GetWidget()->GetNativeView(), overlay_bounds); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.transparent = true; + params.accept_events = false; + params.parent = active_->GetWidget()->GetNativeView(); + params.bounds = overlay_bounds; + active_overlay_->Init(params); overlay_view_ = new OverlayContentView(this); overlay_view_->set_background( views::Background::CreateSolidBackground(SK_ColorWHITE)); diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble.cc b/chrome/browser/ui/views/fullscreen_exit_bubble.cc index 98bb8c5..9f79e5f 100644 --- a/chrome/browser/ui/views/fullscreen_exit_bubble.cc +++ b/chrome/browser/ui/views/fullscreen_exit_bubble.cc @@ -132,13 +132,15 @@ FullscreenExitBubble::FullscreenExitBubble( this, UTF16ToWideHack(accelerator.GetShortcutText())); // Initialize the popup. + popup_ = views::Widget::CreateWidget(); + popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity)); views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = true; params.can_activate = false; params.delete_on_destroy = false; - popup_ = views::Widget::CreateWidget(params); - popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity)); - popup_->Init(frame->GetNativeView(), GetPopupRect(false)); + params.parent = frame->GetNativeView(); + params.bounds = GetPopupRect(false); + popup_->Init(params); popup_->SetContentsView(view_); popup_->Show(); // This does not activate the popup. diff --git a/chrome/browser/ui/views/generic_info_view_unittest.cc b/chrome/browser/ui/views/generic_info_view_unittest.cc index bfefb72..a3c8f0f 100644 --- a/chrome/browser/ui/views/generic_info_view_unittest.cc +++ b/chrome/browser/ui/views/generic_info_view_unittest.cc @@ -23,11 +23,6 @@ using namespace views; class GenericInfoViewTest : public testing::Test { - public: - Widget* CreateWidget() { - return views::Widget::CreateWidget( - Widget::CreateParams(Widget::CreateParams::TYPE_POPUP)); - } private: MessageLoopForUI message_loop_; }; @@ -36,8 +31,10 @@ TEST_F(GenericInfoViewTest, GenericInfoView) { const string16 kName = ASCIIToUTF16("Name"); const string16 kValue = ASCIIToUTF16("Value"); - Widget* widget = CreateWidget(); - widget->Init(NULL, gfx::Rect(0, 0, 100, 100)); + Widget* widget = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); + params.bounds = gfx::Rect(0, 0, 100, 100); + widget->Init(params); RootView* root_view = widget->GetRootView(); GenericInfoView* view1 = new GenericInfoView(1); diff --git a/chrome/browser/ui/views/native_constrained_window_win.cc b/chrome/browser/ui/views/native_constrained_window_win.cc index 96facbe..dc1b7d6 100644 --- a/chrome/browser/ui/views/native_constrained_window_win.cc +++ b/chrome/browser/ui/views/native_constrained_window_win.cc @@ -19,10 +19,6 @@ class NativeConstrainedWindowWin : public NativeConstrainedWindow, views::WindowDelegate* window_delegate) : WindowWin(window_delegate), delegate_(delegate) { - views::Widget::CreateParams params( - views::Widget::CreateParams::TYPE_WINDOW); - params.child = true; - SetCreateParams(params); } virtual ~NativeConstrainedWindowWin() { @@ -31,7 +27,11 @@ class NativeConstrainedWindowWin : public NativeConstrainedWindow, private: // Overridden from NativeConstrainedWindow: virtual void InitNativeConstrainedWindow(gfx::NativeView parent) OVERRIDE { - WindowWin::Init(parent, gfx::Rect()); + views::Widget::CreateParams params( + views::Widget::CreateParams::TYPE_WINDOW); + params.child = true; + params.parent = parent; + GetWidget()->Init(params); } virtual views::NativeWindow* AsNativeWindow() OVERRIDE { return this; diff --git a/chrome/browser/ui/views/notifications/balloon_view.cc b/chrome/browser/ui/views/notifications/balloon_view.cc index cdd4a5a..c1827d3 100644 --- a/chrome/browser/ui/views/notifications/balloon_view.cc +++ b/chrome/browser/ui/views/notifications/balloon_view.cc @@ -316,19 +316,20 @@ void BalloonViewImpl::Show(Balloon* balloon) { gfx::Rect contents_rect = GetContentsRectangle(); html_contents_.reset(new BalloonViewHost(balloon)); html_contents_->SetPreferredSize(gfx::Size(10000, 10000)); - Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); - params.mirror_origin_in_rtl = false; - html_container_ = Widget::CreateWidget(params); + html_container_ = Widget::CreateWidget(); html_container_->SetAlwaysOnTop(true); - html_container_->Init(NULL, contents_rect); + Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); + params.bounds = contents_rect; + html_container_->Init(params); html_container_->SetContentsView(html_contents_->view()); gfx::Rect balloon_rect(x(), y(), GetTotalWidth(), GetTotalHeight()); - params.transparent = true; - frame_container_ = Widget::CreateWidget(params); + frame_container_ = Widget::CreateWidget(); frame_container_->set_widget_delegate(this); frame_container_->SetAlwaysOnTop(true); - frame_container_->Init(NULL, balloon_rect); + params.transparent = true; + params.bounds = balloon_rect; + frame_container_->Init(params); frame_container_->SetContentsView(this); frame_container_->MoveAboveWidget(html_container_); diff --git a/chrome/browser/ui/views/status_bubble_views.cc b/chrome/browser/ui/views/status_bubble_views.cc index 6251845..ec387f0 100644 --- a/chrome/browser/ui/views/status_bubble_views.cc +++ b/chrome/browser/ui/views/status_bubble_views.cc @@ -559,18 +559,19 @@ StatusBubbleViews::~StatusBubbleViews() { void StatusBubbleViews::Init() { if (!popup_.get()) { - Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); - params.transparent = true; - params.accept_events = false; - params.delete_on_destroy = false; - popup_.reset(Widget::CreateWidget(params)); + popup_.reset(Widget::CreateWidget()); views::Widget* frame = base_view_->GetWidget(); if (!view_) view_ = new StatusView(this, popup_.get(), frame->GetThemeProvider()); if (!expand_view_.get()) expand_view_.reset(new StatusViewExpander(this, view_)); popup_->SetOpacity(0x00); - popup_->Init(frame->GetNativeView(), gfx::Rect()); + Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); + params.transparent = true; + params.accept_events = false; + params.delete_on_destroy = false; + params.parent = frame->GetNativeView(); + popup_->Init(params); popup_->SetContentsView(view_); Reposition(); popup_->Show(); diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc index 84625a1..566f9d0 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc @@ -30,9 +30,9 @@ HWND GetHiddenTabHostWindow() { static views::Widget* widget = NULL; if (!widget) { + widget = views::Widget::CreateWidget(); views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); - widget = views::Widget::CreateWidget(params); - widget->Init(NULL, gfx::Rect()); + widget->Init(params); // If a background window requests focus, the hidden tab host will // be activated to focus the tab. Use WS_DISABLED to prevent // this. @@ -72,8 +72,8 @@ void NativeTabContentsViewWin::EndDragging() { void NativeTabContentsViewWin::InitNativeTabContentsView() { views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); params.delete_on_destroy = false; - SetCreateParams(params); - WidgetWin::Init(GetHiddenTabHostWindow(), gfx::Rect()); + params.parent = GetHiddenTabHostWindow(); + GetWidget()->Init(params); // Remove the root view drop target so we can register our own. RevokeDragDrop(GetNativeView()); diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.cc index 18f815c..20eff86 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.cc @@ -103,7 +103,6 @@ TabContentsView* TabContentsView::Create(TabContents* tab_contents) { TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) : TabContentsView(tab_contents), - views::WidgetGtk(TYPE_CHILD), sad_tab_(NULL), ignore_next_char_event_(false) { drag_source_.reset(new TabContentsDragSource(this)); @@ -150,9 +149,10 @@ void TabContentsViewGtk::RemoveConstrainedWindow( } void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { - set_delete_on_destroy(false); - WidgetGtk::Init(NULL, gfx::Rect(0, 0, initial_size.width(), - initial_size.height())); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); + params.delete_on_destroy = false; + params.bounds = gfx::Rect(initial_size); + GetWidget()->Init(params); // We need to own the widget in order to attach/detach the native view // to container. gtk_object_ref(GTK_OBJECT(GetNativeView())); diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc index fb8e74a..629368c 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc @@ -203,13 +203,14 @@ class DraggedTabController::DockDisplayer : public ui::AnimationDelegate { hidden_(false), in_enable_area_(info.in_enable_area()) { #if defined(OS_WIN) + popup_ = views::Widget::CreateWidget(); + popup_->SetOpacity(0x00); // 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()); + params.bounds = info.GetPopupRect(); + popup_->Init(params); popup_->SetContentsView(new DockView(info.type())); if (info.in_enable_area()) animation_.Reset(1); diff --git a/chrome/browser/ui/views/tabs/dragged_tab_view.cc b/chrome/browser/ui/views/tabs/dragged_tab_view.cc index da99f34..18ca918 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_view.cc @@ -39,11 +39,7 @@ 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)); + container_.reset(views::Widget::CreateWidget()); #if defined(OS_WIN) static_cast<views::WidgetWin*>(container_.get())-> set_can_update_layered_window(false); @@ -54,11 +50,15 @@ DraggedTabView::DraggedTabView(const std::vector<views::View*>& renderers, show_contents_on_drag_ = false; } #endif - gfx::Size container_size(PreferredContainerSize()); - container_->Init(NULL, gfx::Rect(gfx::Point(), container_size)); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.transparent = true; + params.keep_on_top = true; + params.delete_on_destroy = false; + params.bounds = gfx::Rect(PreferredContainerSize()); + container_->Init(params); container_->SetContentsView(this); container_->SetOpacity(kTransparentAlpha); - container_->SetBounds(gfx::Rect(gfx::Point(), container_size)); + container_->SetBounds(gfx::Rect(gfx::Point(), params.bounds.size())); } DraggedTabView::~DraggedTabView() { 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 124d8e2..cbd90e2 100644 --- a/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc +++ b/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc @@ -151,12 +151,13 @@ void NativeViewPhotoboothWin::CreateCaptureWindow(HWND initial_hwnd) { gfx::Rect capture_bounds(window_position.x(), window_position.y(), contents_rect.right - contents_rect.left, contents_rect.bottom - contents_rect.top); + capture_window_ = views::Widget::CreateWidget(); views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = true; - capture_window_ = views::Widget::CreateWidget(params); + params.bounds = capture_bounds; + capture_window_->Init(params); // If the capture window isn't visible, blitting from the TabContents' // HWND's DC to the capture bitmap produces blankness. - capture_window_->Init(NULL, capture_bounds); capture_window_->Show(); SetLayeredWindowAttributes( capture_window_->GetNativeView(), RGB(0xFF, 0xFF, 0xFF), 0xFF, LWA_ALPHA); diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc index 728f3ac..83b3e69 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.cc +++ b/chrome/browser/ui/views/tabs/tab_strip.cc @@ -860,15 +860,14 @@ TabStrip::DropInfo::DropInfo(int drop_index, bool drop_before, bool point_down) arrow_view = new views::ImageView; arrow_view->SetImage(GetDropArrowImage(point_down)); + arrow_window = views::Widget::CreateWidget(); 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)); + params.bounds = gfx::Rect(drop_indicator_width, drop_indicator_height); + arrow_window->Init(params); arrow_window->SetContentsView(arrow_view); } diff --git a/chrome/browser/ui/views/theme_install_bubble_view.cc b/chrome/browser/ui/views/theme_install_bubble_view.cc index a3136aa..f04ef8b 100644 --- a/chrome/browser/ui/views/theme_install_bubble_view.cc +++ b/chrome/browser/ui/views/theme_install_bubble_view.cc @@ -70,13 +70,13 @@ ThemeInstallBubbleView::ThemeInstallBubbleView(TabContents* tab_contents) NotificationType::EXTENSION_WILL_SHOW_CONFIRM_DIALOG, NotificationService::AllSources()); - gfx::Rect rc(0, 0, 0, 0); + popup_ = views::Widget::CreateWidget(); + popup_->SetOpacity(0xCC); views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; - popup_ = views::Widget::CreateWidget(params); - popup_->SetOpacity(0xCC); - popup_->Init(tab_contents->GetNativeView(), rc); + params.parent = tab_contents->GetNativeView(); + popup_->Init(params); popup_->SetContentsView(this); Reposition(); popup_->Show(); diff --git a/views/controls/menu/menu_host.cc b/views/controls/menu/menu_host.cc index ce53f92..b8ad997 100644 --- a/views/controls/menu/menu_host.cc +++ b/views/controls/menu/menu_host.cc @@ -22,10 +22,6 @@ MenuHost::MenuHost(SubmenuView* submenu) NativeMenuHost::CreateNativeMenuHost(this))), submenu_(submenu), destroying_(false) { - Widget::CreateParams params; - params.type = Widget::CreateParams::TYPE_MENU; - params.has_dropshadow = true; - GetWidget()->SetCreateParams(params); } MenuHost::~MenuHost() { @@ -35,7 +31,16 @@ void MenuHost::InitMenuHost(gfx::NativeWindow parent, const gfx::Rect& bounds, View* contents_view, bool do_capture) { - native_menu_host_->InitMenuHost(parent, bounds); + Widget::CreateParams params; + params.type = Widget::CreateParams::TYPE_MENU; + params.has_dropshadow = true; +#if defined(OS_WIN) + params.parent = parent; +#elif defined(TOOLKIT_USES_GTK) + params.parent = GTK_WIDGET(parent); +#endif + params.bounds = bounds; + GetWidget()->Init(params); GetWidget()->SetContentsView(contents_view); ShowMenuHost(do_capture); } diff --git a/views/controls/menu/menu_host_gtk.cc b/views/controls/menu/menu_host_gtk.cc index fed765d..914b135 100644 --- a/views/controls/menu/menu_host_gtk.cc +++ b/views/controls/menu/menu_host_gtk.cc @@ -23,8 +23,7 @@ namespace views { // MenuHostGtk, public: MenuHostGtk::MenuHostGtk(internal::NativeMenuHostDelegate* delegate) - : WidgetGtk(WidgetGtk::TYPE_POPUP), - did_input_grab_(false), + : did_input_grab_(false), delegate_(delegate) { } @@ -34,16 +33,6 @@ MenuHostGtk::~MenuHostGtk() { //////////////////////////////////////////////////////////////////////////////// // MenuHostGtk, NativeMenuHost implementation: -void MenuHostGtk::InitMenuHost(gfx::NativeWindow parent, - const gfx::Rect& bounds) { - make_transient_to_parent(); - WidgetGtk::Init(GTK_WIDGET(parent), bounds); - // Make sure we get destroyed when the parent is destroyed. - gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE); - gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()), - GDK_WINDOW_TYPE_HINT_MENU); -} - void MenuHostGtk::StartCapturing() { DCHECK(!did_input_grab_); @@ -92,6 +81,15 @@ NativeWidget* MenuHostGtk::AsNativeWidget() { //////////////////////////////////////////////////////////////////////////////// // MenuHostGtk, WidgetGtk overrides: +void MenuHostGtk::InitNativeWidget(const Widget::CreateParams& params) { + make_transient_to_parent(); + WidgetGtk::InitNativeWidget(params); + // Make sure we get destroyed when the parent is destroyed. + gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE); + gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()), + GDK_WINDOW_TYPE_HINT_MENU); +} + // TODO(beng): remove once MenuHost is-a Widget RootView* MenuHostGtk::CreateRootView() { return delegate_->CreateRootView(); diff --git a/views/controls/menu/menu_host_gtk.h b/views/controls/menu/menu_host_gtk.h index 403a4d0..6ba471f 100644 --- a/views/controls/menu/menu_host_gtk.h +++ b/views/controls/menu/menu_host_gtk.h @@ -24,12 +24,11 @@ class MenuHostGtk : public WidgetGtk, private: // Overridden from NativeMenuHost: - virtual void InitMenuHost(gfx::NativeWindow parent, - const gfx::Rect& bounds) OVERRIDE; virtual void StartCapturing() OVERRIDE; virtual NativeWidget* AsNativeWidget() OVERRIDE; // Overridden from WidgetGtk: + virtual void InitNativeWidget(const Widget::CreateParams& params) OVERRIDE; virtual RootView* CreateRootView() OVERRIDE; virtual bool ShouldReleaseCaptureOnMouseReleased() const OVERRIDE; virtual void ReleaseMouseCapture() OVERRIDE; diff --git a/views/controls/menu/menu_host_win.cc b/views/controls/menu/menu_host_win.cc index 79387e4..5c2435d 100644 --- a/views/controls/menu/menu_host_win.cc +++ b/views/controls/menu/menu_host_win.cc @@ -21,11 +21,6 @@ MenuHostWin::~MenuHostWin() { //////////////////////////////////////////////////////////////////////////////// // MenuHostWin, NativeMenuHost implementation: -void MenuHostWin::InitMenuHost(gfx::NativeWindow parent, - const gfx::Rect& bounds) { - WidgetWin::Init(parent, bounds); -} - void MenuHostWin::StartCapturing() { SetMouseCapture(); } diff --git a/views/controls/menu/menu_host_win.h b/views/controls/menu/menu_host_win.h index 1558a6e..01a1419 100644 --- a/views/controls/menu/menu_host_win.h +++ b/views/controls/menu/menu_host_win.h @@ -23,8 +23,6 @@ class MenuHostWin : public WidgetWin, private: // Overridden from NativeMenuHost: - virtual void InitMenuHost(gfx::NativeWindow parent, - const gfx::Rect& bounds) OVERRIDE; virtual void StartCapturing() OVERRIDE; virtual NativeWidget* AsNativeWidget() OVERRIDE; diff --git a/views/controls/menu/native_menu_host.h b/views/controls/menu/native_menu_host.h index 0b64ca9..8a1a0f8 100644 --- a/views/controls/menu/native_menu_host.h +++ b/views/controls/menu/native_menu_host.h @@ -24,10 +24,6 @@ class NativeMenuHost { static NativeMenuHost* CreateNativeMenuHost( internal::NativeMenuHostDelegate* delegate); - // Initializes and shows the MenuHost. - virtual void InitMenuHost(gfx::NativeWindow parent, - const gfx::Rect& bounds) = 0; - // Starts capturing input events. virtual void StartCapturing() = 0; diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc index df935db..d2286b3 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc @@ -154,9 +154,9 @@ void NativeTabbedPaneGtk::DoAddTabAtIndex(int index, int tab_count = GetTabCount(); DCHECK(index <= tab_count); - Widget* page_container = Widget::CreateWidget( + Widget* page_container = Widget::CreateWidget(); + page_container->Init( Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); - page_container->Init(NULL, gfx::Rect()); page_container->SetContentsView(contents); page_container->SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); page_container->SetFocusTraversableParentView(this); diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index 91e053f..3d897f6 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -291,9 +291,10 @@ 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_ = Widget::CreateWidget( - Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); - content_window_->Init(tab_control, gfx::Rect()); + content_window_ = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_CONTROL); + params.parent = tab_control; + content_window_->Init(params); // Explicitly setting the WS_EX_LAYOUTRTL property for the HWND (see above // for why we waited until |content_window_| is created before we set this diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc index 92f0e25..e6d385b 100644 --- a/views/controls/textfield/native_textfield_views_unittest.cc +++ b/views/controls/textfield/native_textfield_views_unittest.cc @@ -154,10 +154,10 @@ class NativeTextfieldViewsTest : public ViewsTestBase, ASSERT_FALSE(textfield_); textfield_ = new TestTextfield(style); textfield_->SetController(this); + widget_ = Widget::CreateWidget(); Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); - params.mirror_origin_in_rtl = false; - widget_ = Widget::CreateWidget(params); - widget_->Init(NULL, gfx::Rect(100, 100, 100, 100)); + params.bounds = gfx::Rect(100, 100, 100, 100); + widget_->Init(params); View* container = new View(); widget_->SetContentsView(container); container->AddChildView(textfield_); diff --git a/views/examples/widget_example.cc b/views/examples/widget_example.cc index d72276c..537c028f 100644 --- a/views/examples/widget_example.cc +++ b/views/examples/widget_example.cc @@ -108,9 +108,7 @@ void WidgetExample::InitWidget(views::Widget* widget, bool transparent) { #if defined(OS_LINUX) void WidgetExample::CreateChild(views::View* parent, bool transparent) { - views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); - params.transparent = transparent; - views::Widget* widget = views::Widget::CreateWidget(params); + views::Widget* widget = views::Widget::CreateWidget(); // Compute where to place the child widget. // We'll place it at the center of the root widget. views::Widget* parent_widget = parent->GetWidget(); @@ -119,15 +117,16 @@ void WidgetExample::CreateChild(views::View* parent, bool transparent) { bounds.SetRect((bounds.width() - 200) / 2, (bounds.height() - 200) / 2, 200, 200); // Initialize the child widget with the computed bounds. - widget->InitWithWidget(parent_widget, bounds); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); + params.transparent = transparent; + params.parent_widget = parent_widget; + widget->Init(params); InitWidget(widget, transparent); } #endif 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::CreateWidget(params); + views::Widget* widget = views::Widget::CreateWidget(); // Compute where to place the popup widget. // We'll place it right below the create button. @@ -136,9 +135,13 @@ void WidgetExample::CreatePopup(views::View* parent, bool transparent) { views::View::ConvertPointToScreen(parent, &point); // Add the height of create_button_. point.Offset(0, parent->size().height()); - gfx::Rect bounds(point.x(), point.y(), 200, 300); + // Initialize the popup widget with the computed bounds. - widget->InitWithWidget(parent->GetWidget(), bounds); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); + params.transparent = transparent; + params.parent_widget = parent->GetWidget(); + params.bounds = gfx::Rect(point.x(), point.y(), 200, 300); + widget->Init(params); InitWidget(widget, transparent); } diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc index 82afc17..f34e20d 100644 --- a/views/focus/focus_manager_unittest.cc +++ b/views/focus/focus_manager_unittest.cc @@ -290,15 +290,14 @@ class BorderView : public NativeViewHost { if (child == this && is_add) { if (!widget_) { - widget_ = Widget::CreateWidget( - Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); + widget_ = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_CONTROL); #if defined(OS_WIN) - gfx::NativeView parent_native_view = - parent->GetRootView()->GetWidget()->GetNativeView(); + params.parent = parent->GetRootView()->GetWidget()->GetNativeView(); #elif defined(TOOLKIT_USES_GTK) - gfx::NativeView parent_native_view = native_view(); + params.parent = native_view(); #endif - widget_->Init(parent_native_view, gfx::Rect(0, 0, 0, 0)); + widget_->Init(params); widget_->SetFocusTraversableParentView(this); widget_->SetContentsView(child_); } @@ -1603,40 +1602,40 @@ TEST_F(FocusManagerTest, CreationForNativeRoot) { ASSERT_TRUE(hwnd); // Create a view window parented to native dialog. - WidgetWin widget1; + scoped_ptr<Widget> widget1(Widget::CreateWidget()); Widget::CreateParams params(Widget::CreateParams::TYPE_CONTROL); params.delete_on_destroy = false; - widget1.SetCreateParams(params); - widget1.set_window_style(WS_CHILD); - widget1.Init(hwnd, gfx::Rect(0, 0, 100, 100)); + params.parent = hwnd; + params.bounds = gfx::Rect(0, 0, 100, 100); + widget1->Init(params); // Get the focus manager directly from the first window. Should exist // because the first window is the root widget. - views::FocusManager* focus_manager_member1 = widget1.GetFocusManager(); + views::FocusManager* focus_manager_member1 = widget1->GetFocusManager(); EXPECT_TRUE(focus_manager_member1); // Create another view window parented to the first view window. - WidgetWin widget2; - widget2.SetCreateParams(params); - widget2.Init(widget1.GetNativeView(), gfx::Rect(0, 0, 100, 100)); + scoped_ptr<Widget> widget2(Widget::CreateWidget()); + params.parent = widget1->GetNativeView(); + widget2->Init(params); // Get the focus manager directly from the second window. Should return the // first window's focus manager. - views::FocusManager* focus_manager_member2 = widget2.GetFocusManager(); + views::FocusManager* focus_manager_member2 = widget2->GetFocusManager(); EXPECT_EQ(focus_manager_member2, focus_manager_member1); // Get the focus manager indirectly using the first window handle. Should // return the first window's focus manager. views::FocusManager* focus_manager_indirect = views::FocusManager::GetFocusManagerForNativeView( - widget1.GetNativeView()); + widget1->GetNativeView()); EXPECT_EQ(focus_manager_indirect, focus_manager_member1); // Get the focus manager indirectly using the second window handle. Should // return the first window's focus manager. focus_manager_indirect = views::FocusManager::GetFocusManagerForNativeView( - widget2.GetNativeView()); + widget2->GetNativeView()); EXPECT_EQ(focus_manager_indirect, focus_manager_member1); DestroyWindow(hwnd); diff --git a/views/view_unittest.cc b/views/view_unittest.cc index ce37be9..2a046c2 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -52,11 +52,6 @@ class ViewTest : public ViewsTestBase { virtual ~ViewTest() { } - - Widget* CreateWidget() { - return Widget::CreateWidget( - Widget::CreateParams(Widget::CreateParams::TYPE_WINDOW)); - } }; /* @@ -366,11 +361,11 @@ TEST_F(ViewTest, MouseEvent) { TestView* v2 = new TestView(); v2->SetBounds(100, 100, 100, 100); - scoped_ptr<Widget> widget(CreateWidget()); + scoped_ptr<Widget> widget(Widget::CreateWidget()); Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); params.delete_on_destroy = false; - widget->SetCreateParams(params); - widget->Init(NULL, gfx::Rect(50, 50, 650, 650)); + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); RootView* root = widget->GetRootView(); root->AddChildView(v1); @@ -475,15 +470,11 @@ TEST_F(ViewTest, TouchEvent) { TestView* v3 = new TestViewIgnoreTouch(); v3->SetBounds(0, 0, 100, 100); - scoped_ptr<Widget> window(CreateWidget()); -#if defined(OS_WIN) - // This code would need to be here when we support - // touch on windows? - WidgetWin* window_win = static_cast<WidgetWin*>(window.get()); - window_win->set_delete_on_destroy(false); - window_win->set_window_style(WS_OVERLAPPEDWINDOW); - window_win->Init(NULL, gfx::Rect(50, 50, 650, 650)); -#endif + scoped_ptr<Widget> widget(Widget::CreateWidget()); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.delete_on_destroy = false; + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); RootView* root = window->GetRootView(); root->AddChildView(v1); @@ -578,7 +569,7 @@ TEST_F(ViewTest, TouchEvent) { EXPECT_EQ(NULL, gm->last_view_); EXPECT_EQ(gm->previously_handled_flag_, false); - window->CloseNow(); + widget->CloseNow(); } #endif @@ -673,8 +664,8 @@ TEST_F(ViewTest, DISABLED_Painting) { TEST_F(ViewTest, RemoveNotification) { views::ViewStorage* vs = views::ViewStorage::GetInstance(); - views::Widget* window = CreateWidget(); - views::RootView* root_view = window->GetRootView(); + views::Widget* widget = Widget::CreateWidget(); + views::RootView* root_view = widget->GetRootView(); View* v1 = new View; int s1 = vs->CreateStorageID(); @@ -748,7 +739,7 @@ TEST_F(ViewTest, RemoveNotification) { // Now delete the root view (deleting the window will trigger a delete of the // RootView) and make sure we are notified that the views were removed. - delete window; + delete widget; EXPECT_EQ(stored_views - 10, vs->view_count()); EXPECT_EQ(NULL, vs->RetrieveView(s1)); EXPECT_EQ(NULL, vs->RetrieveView(s12)); @@ -800,8 +791,8 @@ gfx::Point ConvertPointToView(views::View* view, const gfx::Point& p) { } TEST_F(ViewTest, HitTestMasks) { - scoped_ptr<views::Widget> window(CreateWidget()); - views::RootView* root_view = window->GetRootView(); + scoped_ptr<views::Widget> widget(Widget::CreateWidget()); + views::RootView* root_view = widget->GetRootView(); root_view->SetBounds(0, 0, 500, 500); gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); @@ -841,9 +832,11 @@ TEST_F(ViewTest, Textfield) { ui::Clipboard clipboard; - Widget* window = CreateWidget(); - window->Init(NULL, gfx::Rect(0, 0, 100, 100)); - RootView* root_view = window->GetRootView(); + Widget* widget = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.bounds = gfx::Rect(0, 0, 100, 100); + widget->Init(params); + RootView* root_view = widget->GetRootView(); Textfield* textfield = new Textfield(); root_view->AddChildView(textfield); @@ -877,11 +870,11 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) { ui::Clipboard clipboard; - Widget* window = CreateWidget(); -#if defined(OS_WIN) - static_cast<WidgetWin*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100)); -#endif - RootView* root_view = window->GetRootView(); + Widget* widget = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.bounds = gfx::Rect(0, 0, 100, 100); + widget->Init(params); + RootView* root_view = widget->GetRootView(); Textfield* normal = new Textfield(); Textfield* read_only = new Textfield(); @@ -1001,17 +994,18 @@ TEST_F(ViewTest, ActivateAccelerator) { EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); // Create a window and add the view as its child. - WidgetWin widget; + scoped_ptr<Widget> widget(Widget::CreateWidget()); Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); params.delete_on_destroy = false; - widget.SetCreateParams(params); - widget.Init(NULL, gfx::Rect(0, 0, 100, 100)); - RootView* root = widget.GetRootView(); + params.bounds = gfx::Rect(0, 0, 100, 100); + widget->Init(params); + RootView* root = widget->GetRootView(); root->AddChildView(view); // Get the focus manager. views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeView(widget.GetNativeView()); + views::FocusManager::GetFocusManagerForNativeView( + widget->GetNativeView()); ASSERT_TRUE(focus_manager); // Hit the return key and see if it takes effect. @@ -1054,7 +1048,7 @@ TEST_F(ViewTest, ActivateAccelerator) { EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); - widget.CloseNow(); + widget->CloseNow(); } #endif @@ -1066,16 +1060,17 @@ TEST_F(ViewTest, HiddenViewWithAccelerator) { view->AddAccelerator(return_accelerator); EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); - WidgetWin widget; + scoped_ptr<Widget> widget(Widget::CreateWidget()); Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); params.delete_on_destroy = false; - widget.SetCreateParams(params); - widget.Init(NULL, gfx::Rect(0, 0, 100, 100)); - RootView* root = widget.GetRootView(); + params.bounds = gfx::Rect(0, 0, 100, 100); + widget->Init(params); + RootView* root = widget->GetRootView(); root->AddChildView(view); views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeView(widget.GetNativeView()); + views::FocusManager::GetFocusManagerForNativeView( + widget->GetNativeView()); ASSERT_TRUE(focus_manager); view->SetVisible(false); @@ -1086,7 +1081,7 @@ TEST_F(ViewTest, HiddenViewWithAccelerator) { EXPECT_EQ(view, focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); - widget.CloseNow(); + widget->CloseNow(); } #endif @@ -1558,12 +1553,17 @@ class TestChangeNativeViewHierarchy { explicit TestChangeNativeViewHierarchy(ViewTest *view_test) { view_test_ = view_test; native_host_ = new views::NativeViewHost(); - host_ = view_test->CreateWidget(); - host_->Init(NULL, gfx::Rect(0, 0, 500, 300)); + host_ = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.bounds = gfx::Rect(0, 0, 500, 300); + host_->Init(params); host_->GetRootView()->AddChildView(native_host_); for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) { - windows_[i] = view_test->CreateWidget(); - windows_[i]->Init(host_->GetNativeView(), gfx::Rect(0, 0, 500, 300)); + windows_[i] = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.parent = host_->GetNativeView(); + params.bounds = gfx::Rect(0, 0, 500, 300); + windows_[i]->Init(params); root_views_[i] = windows_[i]->GetRootView(); test_views_[i] = new TestNativeViewHierarchy; root_views_[i]->AddChildView(test_views_[i]); @@ -1684,12 +1684,10 @@ TEST_F(ViewTest, TransformPaint) { TestView* v2 = new TestView(); v2->SetBounds(100, 100, 200, 100); - Widget* widget = CreateWidget(); -#if defined(OS_WIN) - WidgetWin* window_win = static_cast<WidgetWin*>(widget); - window_win->set_window_style(WS_OVERLAPPEDWINDOW); - window_win->Init(NULL, gfx::Rect(50, 50, 650, 650)); -#endif + Widget* widget = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); widget->Show(); RootView* root = widget->GetRootView(); @@ -1723,12 +1721,10 @@ TEST_F(ViewTest, TransformEvent) { TestView* v2 = new TestView(); v2->SetBounds(100, 100, 200, 100); - Widget* widget = CreateWidget(); -#if defined(OS_WIN) - WidgetWin* window_win = static_cast<WidgetWin*>(widget); - window_win->set_window_style(WS_OVERLAPPEDWINDOW); - window_win->Init(NULL, gfx::Rect(50, 50, 650, 650)); -#endif + Widget* widget = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); RootView* root = widget->GetRootView(); root->AddChildView(v1); @@ -1875,11 +1871,11 @@ class VisibleBoundsView : public View { TEST_F(ViewTest, OnVisibleBoundsChanged) { gfx::Rect viewport_bounds(0, 0, 100, 100); - scoped_ptr<Widget> widget(CreateWidget()); + scoped_ptr<Widget> widget(Widget::CreateWidget()); Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); params.delete_on_destroy = false; - widget->SetCreateParams(params); - widget->Init(NULL, viewport_bounds); + params.bounds = viewport_bounds; + widget->Init(params); widget->GetRootView()->SetBoundsRect(viewport_bounds); View* viewport = new View; diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h index b7692f3..1dba231 100644 --- a/views/widget/native_widget.h +++ b/views/widget/native_widget.h @@ -58,8 +58,8 @@ class NativeWidget { static void ReparentNativeView(gfx::NativeView native_view, gfx::NativeView new_parent); - // Sets the create params for the NativeWidget. - virtual void SetCreateParams(const Widget::CreateParams& params) = 0; + // Initializes the NativeWidget. + virtual void InitNativeWidget(const Widget::CreateParams& params) = 0; // Returns the Widget associated with this NativeWidget. This function is // guaranteed to return non-NULL for the lifetime of the NativeWidget. diff --git a/views/widget/native_widget_test_utils_gtk.cc b/views/widget/native_widget_test_utils_gtk.cc index 43c0279..be6e129 100644 --- a/views/widget/native_widget_test_utils_gtk.cc +++ b/views/widget/native_widget_test_utils_gtk.cc @@ -5,7 +5,8 @@ #include "views/widget/native_widget_test_utils.h" #include "views/view.h" -#include "views/widget/widget_gtk.h" +#include "views/widget/native_widget.h" +#include "views/widget/widget.h" namespace views { namespace internal { @@ -15,18 +16,22 @@ NativeWidget* CreateNativeWidget() { } NativeWidget* CreateNativeWidgetWithContents(View* contents_view) { - WidgetGtk* widget = new WidgetGtk(WidgetGtk::TYPE_WINDOW); - widget->set_delete_on_destroy(false); - widget->Init(NULL, gfx::Rect(10, 10, 200, 200)); - return widget; + Widget* widget = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.delete_on_destroy = false; + params.bounds = gfx::Rect(10, 10, 200, 200); + widget->Init(params); + return widget->native_widget(); } NativeWidget* CreateNativeWidgetWithParent(NativeWidget* parent) { - WidgetGtk* widget = new WidgetGtk(WidgetGtk::TYPE_CHILD); - widget->set_delete_on_destroy(false); - widget->Init(parent ? parent->GetWidget()->GetNativeView() : NULL, - gfx::Rect(10, 10, 200, 200)); - return widget; + Widget* widget = Widget::CreateWidget(); + Widget::CreateParams params(Widget::CreateParams::TYPE_CONTROL); + params.delete_on_destroy = false; + params.parent = parent ? parent->GetWidget()->GetNativeView() : NULL; + params.bounds = gfx::Rect(10, 10, 200, 200); + widget->Init(params); + return widget->native_widget(); } } // namespace internal diff --git a/views/widget/native_widget_test_utils_win.cc b/views/widget/native_widget_test_utils_win.cc index 85a5fe9..37b7d27 100644 --- a/views/widget/native_widget_test_utils_win.cc +++ b/views/widget/native_widget_test_utils_win.cc @@ -15,23 +15,23 @@ NativeWidget* CreateNativeWidget() { } NativeWidget* CreateNativeWidgetWithContents(View* contents_view) { - WidgetWin* widget = new WidgetWin; + Widget* widget = Widget::CreateWidget(); Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); params.delete_on_destroy = false; - widget->SetCreateParams(params); - widget->Init(NULL, gfx::Rect(10, 10, 200, 200)); - return widget; + params.bounds = gfx::Rect(10, 10, 200, 200); + widget->Init(params); + return widget->native_widget(); } NativeWidget* CreateNativeWidgetWithParent(NativeWidget* parent) { - WidgetWin* widget = new WidgetWin; + Widget* widget = Widget::CreateWidget(); Widget::CreateParams params(Widget::CreateParams::TYPE_CONTROL); params.delete_on_destroy = false; params.child = false; // Implicitly set to true by ctor with TYPE_CONTROL. - widget->SetCreateParams(params); - widget->Init(parent ? parent->GetWidget()->GetNativeView() : NULL, - gfx::Rect(10, 10, 200, 200)); - return widget; + params.parent = parent ? parent->GetWidget()->GetNativeView() : NULL; + params.bounds = gfx::Rect(10, 10, 200, 200); + widget->Init(params); + return widget->native_widget(); } } // namespace internal diff --git a/views/widget/widget.cc b/views/widget/widget.cc index aeaebad8..dd40007 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -28,6 +28,8 @@ Widget::CreateParams::CreateParams() delete_on_destroy(true), mirror_origin_in_rtl(false), has_dropshadow(false), + parent(NULL), + parent_widget(NULL), native_widget(NULL) { } @@ -41,12 +43,19 @@ Widget::CreateParams::CreateParams(Type type) delete_on_destroy(true), mirror_origin_in_rtl(false), has_dropshadow(false), + parent(NULL), + parent_widget(NULL), native_widget(NULL) { } //////////////////////////////////////////////////////////////////////////////// // Widget, public: +// static +Widget::CreateParams Widget::WindowCreateParams() { + return CreateParams(CreateParams::TYPE_WINDOW); +} + Widget::Widget() : is_mouse_button_pressed_(false), last_mouse_event_was_move_(false), @@ -58,19 +67,13 @@ Widget::Widget() Widget::~Widget() { } -void Widget::SetCreateParams(const CreateParams& params) { - native_widget_->SetCreateParams(params); -} - -// Unconverted methods (see header) -------------------------------------------- - -void Widget::Init(gfx::NativeView parent, const gfx::Rect& bounds) { +void Widget::Init(const CreateParams& params) { GetRootView(); default_theme_provider_.reset(new DefaultThemeProvider); + native_widget_->InitNativeWidget(params); } -void Widget::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { -} +// Unconverted methods (see header) -------------------------------------------- gfx::NativeView Widget::GetNativeView() const { return NULL; diff --git a/views/widget/widget.h b/views/widget/widget.h index d2c17a7..ec33496 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -12,6 +12,7 @@ #include "base/memory/scoped_ptr.h" #include "ui/base/accessibility/accessibility_types.h" #include "ui/gfx/native_widget_types.h" +#include "ui/gfx/rect.h" #include "views/focus/focus_manager.h" #include "views/widget/native_widget_delegate.h" @@ -61,6 +62,7 @@ class Window; class Widget : public internal::NativeWidgetDelegate, public FocusTraversable { public: + // TODO(beng): Rename to InitParams now this is required for Init(). struct CreateParams { enum Type { TYPE_WINDOW, // A Window, like a frame window. @@ -74,7 +76,6 @@ class Widget : public internal::NativeWidgetDelegate, explicit CreateParams(Type type); Type type; - bool child; bool transparent; bool accept_events; @@ -83,14 +84,18 @@ class Widget : public internal::NativeWidgetDelegate, bool delete_on_destroy; bool mirror_origin_in_rtl; bool has_dropshadow; + gfx::NativeView parent; + Widget* parent_widget; + gfx::Rect bounds; NativeWidget* native_widget; }; + static CreateParams WindowCreateParams(); Widget(); virtual ~Widget(); // Creates a Widget instance with the supplied params. - static Widget* CreateWidget(const CreateParams& params); + static Widget* CreateWidget(); // Enumerates all windows pertaining to us and notifies their // view hierarchies that the locale has changed. @@ -104,8 +109,7 @@ class Widget : public internal::NativeWidgetDelegate, const Widget* target, gfx::Rect* rect); - // Sets the creation params for the Widget. - void SetCreateParams(const CreateParams& params); + void Init(const CreateParams& params); // Unconverted methods ------------------------------------------------------- @@ -113,16 +117,6 @@ class Widget : public internal::NativeWidgetDelegate, // Widget subclasses are still implementing these methods by overriding from // here rather than by implementing NativeWidget. - // Initialize the Widget with a parent and an initial desired size. - // |contents_view| is the view that will be the single child of RootView - // within this Widget. As contents_view is inserted into RootView's tree, - // RootView assumes ownership of this view and cleaning it up. If you remove - // this view, you are responsible for its destruction. If this value is NULL, - // the caller is responsible for populating the RootView, and sizing its - // contents as the window is sized. - virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); - virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); - // Returns the gfx::NativeView associated with this Widget. virtual gfx::NativeView GetNativeView() const; diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 85b361c..827c97c 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -283,12 +283,12 @@ bool WidgetGtk::debug_paint_enabled_ = false; //////////////////////////////////////////////////////////////////////////////// // WidgetGtk, public: -WidgetGtk::WidgetGtk(Type type) +WidgetGtk::WidgetGtk() : is_window_(false), ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)), - type_(type), widget_(NULL), window_contents_(NULL), + child_(false), ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), delete_on_destroy_(true), transparent_(false), @@ -326,12 +326,10 @@ WidgetGtk::~WidgetGtk() { input_method_.reset(); DestroyRootView(); DCHECK(delete_on_destroy_ || widget_ == NULL); - if (type_ != TYPE_CHILD) - ActiveWindowWatcherX::RemoveObserver(this); } GtkWindow* WidgetGtk::GetTransientParent() const { - return (type_ != TYPE_CHILD && widget_) ? + return (!child_ && widget_) ? gtk_window_get_transient_for(GTK_WINDOW(widget_)) : NULL; } @@ -366,15 +364,6 @@ void WidgetGtk::EnableDoubleBuffer(bool enabled) { } } -bool WidgetGtk::MakeIgnoreEvents() { - // Transparency can only be enabled for windows/popups and only if we haven't - // realized the widget. - DCHECK(!widget_ && type_ != TYPE_CHILD); - - ignore_events_ = true; - return true; -} - void WidgetGtk::AddChild(GtkWidget* child) { gtk_container_add(GTK_CONTAINER(window_contents_), child); } @@ -490,7 +479,7 @@ void WidgetGtk::ActiveWindowChanged(GdkWindow* active_window) { bool was_active = IsActive(); is_active_ = (active_window == GTK_WIDGET(GetNativeView())->window); - if (!is_active_ && active_window && type_ != TYPE_CHILD) { + if (!is_active_ && active_window && !child_) { // We're not active, but the force the window to be rendered as active if // a child window is transient to us. gpointer data = NULL; @@ -510,151 +499,6 @@ void WidgetGtk::ActiveWindowChanged(GdkWindow* active_window) { //////////////////////////////////////////////////////////////////////////////// // WidgetGtk, Widget implementation: -void WidgetGtk::InitWithWidget(Widget* parent, - const gfx::Rect& bounds) { - WidgetGtk* parent_gtk = static_cast<WidgetGtk*>(parent); - GtkWidget* native_parent = NULL; - if (parent != NULL) { - if (type_ != TYPE_CHILD) { - // window's parent has to be window. - native_parent = parent_gtk->GetNativeView(); - } else { - native_parent = parent_gtk->window_contents(); - } - } - Init(native_parent, bounds); -} - -void WidgetGtk::Init(GtkWidget* parent, - const gfx::Rect& bounds) { - Widget::Init(parent, bounds); - if (type_ != TYPE_CHILD) - ActiveWindowWatcherX::AddObserver(this); - - // Make container here. - CreateGtkWidget(parent, bounds); - delegate_->OnNativeWidgetCreated(); - - // Creates input method for toplevel widget after calling - // delegate_->OnNativeWidgetCreated(), to make sure that focus manager is - // already created at this point. - // TODO(suzhe): Always enable input method when we start to use - // RenderWidgetHostViewViews in normal ChromeOS. -#if defined(TOUCH_UI) && defined(HAVE_IBUS) - if (type_ != TYPE_CHILD) { - input_method_.reset(new InputMethodIBus(this)); -#else - if (type_ != TYPE_CHILD && NativeTextfieldViews::IsTextfieldViewsEnabled()) { - input_method_.reset(new InputMethodGtk(this)); -#endif - input_method_->Init(GetWidget()); - } - - if (opacity_ != 255) - SetOpacity(opacity_); - - // Make sure we receive our motion events. - - // In general we register most events on the parent of all widgets. At a - // minimum we need painting to happen on the parent (otherwise painting - // doesn't work at all), and similarly we need mouse release events on the - // parent as windows don't get mouse releases. - gtk_widget_add_events(window_contents_, - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK); - - g_signal_connect_after(G_OBJECT(window_contents_), "size_request", - G_CALLBACK(&OnSizeRequestThunk), this); - g_signal_connect_after(G_OBJECT(window_contents_), "size_allocate", - G_CALLBACK(&OnSizeAllocateThunk), this); - gtk_widget_set_app_paintable(window_contents_, true); - g_signal_connect(window_contents_, "expose_event", - G_CALLBACK(&OnPaintThunk), this); - g_signal_connect(window_contents_, "enter_notify_event", - G_CALLBACK(&OnEnterNotifyThunk), this); - g_signal_connect(window_contents_, "leave_notify_event", - G_CALLBACK(&OnLeaveNotifyThunk), this); - g_signal_connect(window_contents_, "motion_notify_event", - G_CALLBACK(&OnMotionNotifyThunk), this); - g_signal_connect(window_contents_, "button_press_event", - G_CALLBACK(&OnButtonPressThunk), this); - g_signal_connect(window_contents_, "button_release_event", - G_CALLBACK(&OnButtonReleaseThunk), this); - g_signal_connect(window_contents_, "grab_broken_event", - G_CALLBACK(&OnGrabBrokeEventThunk), this); - g_signal_connect(window_contents_, "grab_notify", - G_CALLBACK(&OnGrabNotifyThunk), this); - g_signal_connect(window_contents_, "scroll_event", - G_CALLBACK(&OnScrollThunk), this); - g_signal_connect(window_contents_, "visibility_notify_event", - G_CALLBACK(&OnVisibilityNotifyThunk), this); - - // In order to receive notification when the window is no longer the front - // window, we need to install these on the widget. - // NOTE: this doesn't work with focus follows mouse. - g_signal_connect(widget_, "focus_in_event", - G_CALLBACK(&OnFocusInThunk), this); - g_signal_connect(widget_, "focus_out_event", - G_CALLBACK(&OnFocusOutThunk), this); - g_signal_connect(widget_, "destroy", - G_CALLBACK(&OnDestroyThunk), this); - g_signal_connect(widget_, "show", - G_CALLBACK(&OnShowThunk), this); - g_signal_connect(widget_, "map", - G_CALLBACK(&OnMapThunk), this); - g_signal_connect(widget_, "hide", - G_CALLBACK(&OnHideThunk), this); - - // Views/FocusManager (re)sets the focus to the root window, - // so we need to connect signal handlers to the gtk window. - // See views::Views::Focus and views::FocusManager::ClearNativeFocus - // for more details. - g_signal_connect(widget_, "key_press_event", - G_CALLBACK(&OnEventKeyThunk), this); - g_signal_connect(widget_, "key_release_event", - G_CALLBACK(&OnEventKeyThunk), this); - - // Drag and drop. - gtk_drag_dest_set(window_contents_, static_cast<GtkDestDefaults>(0), - NULL, 0, GDK_ACTION_COPY); - g_signal_connect(window_contents_, "drag_motion", - G_CALLBACK(&OnDragMotionThunk), this); - g_signal_connect(window_contents_, "drag_data_received", - G_CALLBACK(&OnDragDataReceivedThunk), this); - g_signal_connect(window_contents_, "drag_drop", - G_CALLBACK(&OnDragDropThunk), this); - g_signal_connect(window_contents_, "drag_leave", - G_CALLBACK(&OnDragLeaveThunk), this); - g_signal_connect(window_contents_, "drag_data_get", - G_CALLBACK(&OnDragDataGetThunk), this); - g_signal_connect(window_contents_, "drag_end", - G_CALLBACK(&OnDragEndThunk), this); - g_signal_connect(window_contents_, "drag_failed", - G_CALLBACK(&OnDragFailedThunk), this); - - tooltip_manager_.reset(new TooltipManagerGtk(this)); - - // Register for tooltips. - g_object_set(G_OBJECT(window_contents_), "has-tooltip", TRUE, NULL); - g_signal_connect(window_contents_, "query_tooltip", - G_CALLBACK(&OnQueryTooltipThunk), this); - - if (type_ == TYPE_CHILD) { - if (parent) { - SetBounds(bounds); - } - } else { - if (bounds.width() > 0 && bounds.height() > 0) - gtk_window_resize(GTK_WINDOW(widget_), bounds.width(), bounds.height()); - gtk_window_move(GTK_WINDOW(widget_), bounds.x(), bounds.y()); - } -} - gfx::NativeView WidgetGtk::GetNativeView() const { return widget_; } @@ -691,7 +535,7 @@ void WidgetGtk::NotifyAccessibilityEvent( } void WidgetGtk::ClearNativeFocus() { - DCHECK(type_ != TYPE_CHILD); + DCHECK(!child_); if (!GetNativeView()) { NOTREACHED(); return; @@ -774,25 +618,142 @@ void WidgetGtk::RegisterChildExposeHandler(GtkWidget* child) { //////////////////////////////////////////////////////////////////////////////// // WidgetGtk, NativeWidget implementation: -void WidgetGtk::SetCreateParams(const CreateParams& params) { - DCHECK(!GetNativeView()); +void WidgetGtk::InitNativeWidget(const CreateParams& params) { + SetCreateParams(params); - // Set non-style attributes. - set_delete_on_destroy(params.delete_on_destroy); + CreateParams modified_params = params; + gfx::NativeView parent = params.parent; + if (params.parent_widget) { + WidgetGtk* parent_gtk = + static_cast<WidgetGtk*>(params.parent_widget->native_widget()); + modified_params.parent = child_ ? parent_gtk->window_contents() + : params.parent_widget->GetNativeView(); + } - if (params.transparent) - MakeTransparent(); - if (!params.accept_events) - MakeIgnoreEvents(); + if (!child_) + ActiveWindowWatcherX::AddObserver(this); - if (params.type == CreateParams::TYPE_MENU) { - GdkEvent* event = gtk_get_current_event(); - if (event) { - is_mouse_button_pressed_ = event->type == GDK_BUTTON_PRESS || - event->type == GDK_2BUTTON_PRESS || - event->type == GDK_3BUTTON_PRESS; - gdk_event_free(event); - } + // Make container here. + CreateGtkWidget(modified_params); + delegate_->OnNativeWidgetCreated(); + + // Creates input method for toplevel widget after calling + // delegate_->OnNativeWidgetCreated(), to make sure that focus manager is + // already created at this point. + // TODO(suzhe): Always enable input method when we start to use + // RenderWidgetHostViewViews in normal ChromeOS. +#if defined(TOUCH_UI) && defined(HAVE_IBUS) + if (!child_) { + input_method_.reset(new InputMethodIBus(this)); +#else + if (!child_ && NativeTextfieldViews::IsTextfieldViewsEnabled()) { + input_method_.reset(new InputMethodGtk(this)); +#endif + input_method_->Init(GetWidget()); + } + + if (opacity_ != 255) + SetOpacity(opacity_); + + // Make sure we receive our motion events. + + // In general we register most events on the parent of all widgets. At a + // minimum we need painting to happen on the parent (otherwise painting + // doesn't work at all), and similarly we need mouse release events on the + // parent as windows don't get mouse releases. + gtk_widget_add_events(window_contents_, + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | + GDK_KEY_PRESS_MASK | + GDK_KEY_RELEASE_MASK); + + g_signal_connect_after(G_OBJECT(window_contents_), "size_request", + G_CALLBACK(&OnSizeRequestThunk), this); + g_signal_connect_after(G_OBJECT(window_contents_), "size_allocate", + G_CALLBACK(&OnSizeAllocateThunk), this); + gtk_widget_set_app_paintable(window_contents_, true); + g_signal_connect(window_contents_, "expose_event", + G_CALLBACK(&OnPaintThunk), this); + g_signal_connect(window_contents_, "enter_notify_event", + G_CALLBACK(&OnEnterNotifyThunk), this); + g_signal_connect(window_contents_, "leave_notify_event", + G_CALLBACK(&OnLeaveNotifyThunk), this); + g_signal_connect(window_contents_, "motion_notify_event", + G_CALLBACK(&OnMotionNotifyThunk), this); + g_signal_connect(window_contents_, "button_press_event", + G_CALLBACK(&OnButtonPressThunk), this); + g_signal_connect(window_contents_, "button_release_event", + G_CALLBACK(&OnButtonReleaseThunk), this); + g_signal_connect(window_contents_, "grab_broken_event", + G_CALLBACK(&OnGrabBrokeEventThunk), this); + g_signal_connect(window_contents_, "grab_notify", + G_CALLBACK(&OnGrabNotifyThunk), this); + g_signal_connect(window_contents_, "scroll_event", + G_CALLBACK(&OnScrollThunk), this); + g_signal_connect(window_contents_, "visibility_notify_event", + G_CALLBACK(&OnVisibilityNotifyThunk), this); + + // In order to receive notification when the window is no longer the front + // window, we need to install these on the widget. + // NOTE: this doesn't work with focus follows mouse. + g_signal_connect(widget_, "focus_in_event", + G_CALLBACK(&OnFocusInThunk), this); + g_signal_connect(widget_, "focus_out_event", + G_CALLBACK(&OnFocusOutThunk), this); + g_signal_connect(widget_, "destroy", + G_CALLBACK(&OnDestroyThunk), this); + g_signal_connect(widget_, "show", + G_CALLBACK(&OnShowThunk), this); + g_signal_connect(widget_, "map", + G_CALLBACK(&OnMapThunk), this); + g_signal_connect(widget_, "hide", + G_CALLBACK(&OnHideThunk), this); + + // Views/FocusManager (re)sets the focus to the root window, + // so we need to connect signal handlers to the gtk window. + // See views::Views::Focus and views::FocusManager::ClearNativeFocus + // for more details. + g_signal_connect(widget_, "key_press_event", + G_CALLBACK(&OnEventKeyThunk), this); + g_signal_connect(widget_, "key_release_event", + G_CALLBACK(&OnEventKeyThunk), this); + + // Drag and drop. + gtk_drag_dest_set(window_contents_, static_cast<GtkDestDefaults>(0), + NULL, 0, GDK_ACTION_COPY); + g_signal_connect(window_contents_, "drag_motion", + G_CALLBACK(&OnDragMotionThunk), this); + g_signal_connect(window_contents_, "drag_data_received", + G_CALLBACK(&OnDragDataReceivedThunk), this); + g_signal_connect(window_contents_, "drag_drop", + G_CALLBACK(&OnDragDropThunk), this); + g_signal_connect(window_contents_, "drag_leave", + G_CALLBACK(&OnDragLeaveThunk), this); + g_signal_connect(window_contents_, "drag_data_get", + G_CALLBACK(&OnDragDataGetThunk), this); + g_signal_connect(window_contents_, "drag_end", + G_CALLBACK(&OnDragEndThunk), this); + g_signal_connect(window_contents_, "drag_failed", + G_CALLBACK(&OnDragFailedThunk), this); + + tooltip_manager_.reset(new TooltipManagerGtk(this)); + + // Register for tooltips. + g_object_set(G_OBJECT(window_contents_), "has-tooltip", TRUE, NULL); + g_signal_connect(window_contents_, "query_tooltip", + G_CALLBACK(&OnQueryTooltipThunk), this); + + if (child_) { + if (parent) + SetBounds(params.bounds); + } else { + if (params.bounds.width() > 0 && params.bounds.height() > 0) + gtk_window_resize(GTK_WINDOW(widget_), params.bounds.width(), + params.bounds.height()); + gtk_window_move(GTK_WINDOW(widget_), params.bounds.x(), params.bounds.y()); } } @@ -870,7 +831,7 @@ gfx::Rect WidgetGtk::GetClientAreaScreenBounds() const { } void WidgetGtk::SetBounds(const gfx::Rect& bounds) { - if (type_ == TYPE_CHILD) { + if (child_) { GtkWidget* parent = gtk_widget_get_parent(widget_); if (GTK_IS_VIEWS_FIXED(parent)) { WidgetGtk* parent_widget = static_cast<WidgetGtk*>( @@ -908,7 +869,7 @@ void WidgetGtk::SetBounds(const gfx::Rect& bounds) { } void WidgetGtk::SetSize(const gfx::Size& size) { - if (type_ == TYPE_CHILD) { + if (child_) { GtkWidget* parent = gtk_widget_get_parent(widget_); if (GTK_IS_VIEWS_FIXED(parent)) { gtk_views_fixed_set_widget_size(widget_, size.width(), size.height()); @@ -984,7 +945,7 @@ void WidgetGtk::SetOpacity(unsigned char opacity) { } void WidgetGtk::SetAlwaysOnTop(bool on_top) { - DCHECK(type_ != TYPE_CHILD); + DCHECK(!child_); always_on_top_ = on_top; if (widget_) gtk_window_set_keep_above(GTK_WINDOW(widget_), on_top); @@ -995,7 +956,7 @@ bool WidgetGtk::IsVisible() const { } bool WidgetGtk::IsActive() const { - DCHECK(type_ != TYPE_CHILD); + DCHECK(!child_); return is_active_; } @@ -1048,7 +1009,7 @@ void WidgetGtk::OnSizeRequest(GtkWidget* widget, GtkRequisition* requisition) { // the requisition as a minimum size for top level windows, returning a // preferred size for these would prevents us from setting smaller window // sizes. - if (type_ == TYPE_CHILD) { + if (child_) { gfx::Size size(GetRootView()->GetPreferredSize()); requisition->width = size.width(); requisition->height = size.height(); @@ -1068,7 +1029,7 @@ void WidgetGtk::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { } gboolean WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { - if (transparent_ && type_ == TYPE_CHILD) { + if (transparent_ && child_) { // Clear the background before drawing any view and native components. DrawTransparentBackground(widget, event); if (!CompositePainter::IsComposited(widget_) && @@ -1101,7 +1062,7 @@ gboolean WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { if (!painted_) { painted_ = true; - if (type_ != TYPE_CHILD) + if (!child_) UpdateFreezeUpdatesProperty(GTK_WINDOW(widget_), false /* remove */); } return false; // False indicates other widgets should get the event as well. @@ -1262,7 +1223,7 @@ gboolean WidgetGtk::OnFocusIn(GtkWidget* widget, GdkEventFocus* event) { should_handle_menu_key_release_ = false; - if (type_ == TYPE_CHILD) + if (child_) return false; // Only top-level Widget should have an InputMethod instance. @@ -1282,7 +1243,7 @@ gboolean WidgetGtk::OnFocusOut(GtkWidget* widget, GdkEventFocus* event) { return false; // This is the second focus-out event in a row, ignore it. has_focus_ = false; - if (type_ == TYPE_CHILD) + if (child_) return false; // Only top-level Widget should have an InputMethod instance. @@ -1328,6 +1289,8 @@ void WidgetGtk::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) { } void WidgetGtk::OnDestroy(GtkWidget* object) { + if (!child_) + ActiveWindowWatcherX::RemoveObserver(this); // Note that this handler is hooked to GtkObject::destroy. // NULL out pointers here since we might still be in an observerer list // until delstion happens. @@ -1414,6 +1377,28 @@ void WidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) { gtk_bindings_activate_event(GTK_OBJECT(widget_), event); } +void WidgetGtk::SetCreateParams(const CreateParams& params) { + DCHECK(!GetNativeView()); + + delete_on_destroy_ = params.delete_on_destroy; + child_ = params.child; + + if (params.transparent) + MakeTransparent(); + if (!params.accept_events && !child_) + ignore_events_ = true; + + if (params.type == CreateParams::TYPE_MENU) { + GdkEvent* event = gtk_get_current_event(); + if (event) { + is_mouse_button_pressed_ = event->type == GDK_BUTTON_PRESS || + event->type == GDK_2BUTTON_PRESS || + event->type == GDK_3BUTTON_PRESS; + gdk_event_free(event); + } + } +} + gboolean WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) { // Clear the background to be totally transparent. We don't need to // paint the root view here as that is done by OnPaint. @@ -1430,7 +1415,7 @@ gboolean WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) { } void WidgetGtk::OnChildExpose(GtkWidget* child) { - DCHECK(type_ != TYPE_CHILD); + DCHECK(!child_); if (!painted_) { painted_ = true; UpdateFreezeUpdatesProperty(GTK_WINDOW(widget_), false /* remove */); @@ -1464,7 +1449,7 @@ Window* WidgetGtk::GetWindowImpl(GtkWidget* widget) { return NULL; } -void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { +void WidgetGtk::CreateGtkWidget(const CreateParams& params) { // We turn off double buffering for two reasons: // 1. We draw to a canvas then composite to the screen, which means we're // doing our own double buffering already. @@ -1472,13 +1457,13 @@ void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { // needs to expand the paint region (see RootView::OnPaint). This means // that if we use GTK's double buffering and we tried to expand the dirty // region, it wouldn't get painted. - if (type_ == TYPE_CHILD) { + if (child_) { window_contents_ = widget_ = gtk_views_fixed_new(); gtk_widget_set_name(widget_, "views-gtkwidget-child-fixed"); if (!is_double_buffered_) GTK_WIDGET_UNSET_FLAGS(widget_, GTK_DOUBLE_BUFFERED); gtk_fixed_set_has_window(GTK_FIXED(widget_), true); - if (!parent && !null_parent_) { + if (!params.parent && !null_parent_) { GtkWidget* popup = gtk_window_new(GTK_WINDOW_POPUP); null_parent_ = gtk_fixed_new(); gtk_widget_set_name(widget_, "views-gtkwidget-null-parent"); @@ -1487,10 +1472,12 @@ void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { } if (transparent_) { // transparency has to be configured before widget is realized. - DCHECK(parent) << "Transparent widget must have parent when initialized"; - ConfigureWidgetForTransparentBackground(parent); + DCHECK(params.parent) << + "Transparent widget must have parent when initialized"; + ConfigureWidgetForTransparentBackground(params.parent); } - gtk_container_add(GTK_CONTAINER(parent ? parent : null_parent_), widget_); + gtk_container_add( + GTK_CONTAINER(params.parent ? params.parent : null_parent_), widget_); gtk_widget_realize(widget_); if (transparent_) { // The widget has to be realized to set composited flag. @@ -1499,7 +1486,7 @@ void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { DCHECK(GTK_WIDGET_REALIZED(widget_)); gdk_window_set_composited(widget_->window, true); } - if (parent && !bounds.size().IsEmpty()) { + if (params.parent && !params.bounds.size().IsEmpty()) { // Make sure that an widget is given it's initial size before // we're done initializing, to take care of some potential // corner cases when programmatically arranging hierarchies as @@ -1509,17 +1496,20 @@ void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { // This can't be done without a parent present, or stale data // might show up on the screen as seen in // http://code.google.com/p/chromium/issues/detail?id=53870 - GtkAllocation alloc = { 0, 0, bounds.width(), bounds.height() }; + GtkAllocation alloc = + { 0, 0, params.bounds.width(), params.bounds.height() }; gtk_widget_size_allocate(widget_, &alloc); } } else { // Use our own window class to override GtkWindow's move_focus method. widget_ = gtk_views_window_new( - (type_ == TYPE_WINDOW || type_ == TYPE_DECORATED_WINDOW) ? - GTK_WINDOW_TOPLEVEL : GTK_WINDOW_POPUP); + params.type == CreateParams::TYPE_WINDOW ? GTK_WINDOW_TOPLEVEL + : GTK_WINDOW_POPUP); gtk_widget_set_name(widget_, "views-gtkwidget-window"); - if (transient_to_parent_) - gtk_window_set_transient_for(GTK_WINDOW(widget_), GTK_WINDOW(parent)); + if (transient_to_parent_) { + gtk_window_set_transient_for(GTK_WINDOW(widget_), + GTK_WINDOW(params.parent)); + } GTK_WIDGET_UNSET_FLAGS(widget_, GTK_DOUBLE_BUFFERED); // Gtk determines the size for windows based on the requested size of the @@ -1533,18 +1523,17 @@ void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { // time. gtk_widget_set_size_request(widget_, 1, 1); - if (!bounds.size().IsEmpty()) { + if (!params.bounds.size().IsEmpty()) { // When we realize the window, the window manager is given a size. If we // don't specify a size before then GTK defaults to 200x200. Specify // a size now so that the window manager sees the requested size. - GtkAllocation alloc = { 0, 0, bounds.width(), bounds.height() }; + GtkAllocation alloc = + { 0, 0, params.bounds.width(), params.bounds.height() }; gtk_widget_size_allocate(widget_, &alloc); } - if (type_ != TYPE_DECORATED_WINDOW) { - gtk_window_set_decorated(GTK_WINDOW(widget_), false); - // We'll take care of positioning our window. - gtk_window_set_position(GTK_WINDOW(widget_), GTK_WIN_POS_NONE); - } + gtk_window_set_decorated(GTK_WINDOW(widget_), false); + // We'll take care of positioning our window. + gtk_window_set_position(GTK_WINDOW(widget_), GTK_WIN_POS_NONE); window_contents_ = gtk_views_fixed_new(); gtk_widget_set_name(window_contents_, "views-gtkwidget-window-fixed"); @@ -1582,7 +1571,7 @@ void WidgetGtk::ConfigureWidgetForTransparentBackground(GtkWidget* parent) { // on both the window and fixed. In addition we need to make sure no // decorations are drawn. The last bit is to make sure the widget doesn't // attempt to draw a pixmap in it's background. - if (type_ != TYPE_CHILD) { + if (!child_) { DCHECK(parent == NULL); gtk_widget_set_colormap(widget_, rgba_colormap); gtk_widget_set_app_paintable(widget_, true); @@ -1632,30 +1621,8 @@ void WidgetGtk::DrawTransparentBackground(GtkWidget* widget, // Widget, public: // static -Widget* Widget::CreateWidget(const CreateParams& params) { - // TODO(beng): coalesce with CreateParams::Type. - WidgetGtk::Type widget_gtk_type = WidgetGtk::TYPE_DECORATED_WINDOW; - 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; +Widget* Widget::CreateWidget() { + return new WidgetGtk(); } // static diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index a7ede90..3839754 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -46,27 +46,7 @@ class WidgetGtk : public Widget, public ui::ActiveWindowWatcherX::Observer, public internal::InputMethodDelegate { public: - // Type of widget. - enum Type { - // Used for popup type windows (bubbles, menus ...). - // NOTE: on X windows of this type can NOT get focus. If you need a popup - // like widget that can be focused use TYPE_WINDOW and set the window type - // to WINDOW_TYPE_CHROME_INFO_BUBBLE. - TYPE_POPUP, - - // A top level window with no title or control buttons. - // NOTE: On ChromeOS TYPE_WINDOW and TYPE_DECORATED_WINDOW behave the same. - TYPE_WINDOW, - - // A top level, decorated window. - // NOTE: On ChromeOS TYPE_WINDOW and TYPE_DECORATED_WINDOW behave the same. - TYPE_DECORATED_WINDOW, - - // A child widget. - TYPE_CHILD - }; - - explicit WidgetGtk(Type type); + WidgetGtk(); virtual ~WidgetGtk(); // Marks this window as transient to its parent. A window that is transient @@ -98,19 +78,8 @@ class WidgetGtk : public Widget, void EnableDoubleBuffer(bool enabled); bool is_double_buffered() const { return is_double_buffered_; } - // Makes the window pass all events through to any windows behind it. - // This must be invoked before Init. This does a couple of checks and returns - // true if the window can be made to ignore events. The actual work of making - // the window ignore events is done by ConfigureWidgetForIgnoreEvents. - bool MakeIgnoreEvents(); bool is_ignore_events() const { return ignore_events_; } - // Sets whether or not we are deleted when the widget is destroyed. The - // default is true. - void set_delete_on_destroy(bool delete_on_destroy) { - delete_on_destroy_ = delete_on_destroy; - } - // Adds and removes the specified widget as a child of this widget's contents. // These methods make sure to add the widget to the window's contents // container if this widget is a window. @@ -155,8 +124,6 @@ class WidgetGtk : public Widget, virtual void ActiveWindowChanged(GdkWindow* active_window); // Overridden from Widget: - virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); - virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); virtual gfx::NativeView GetNativeView() const; virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); virtual Window* GetWindow(); @@ -201,7 +168,7 @@ class WidgetGtk : public Widget, static void RegisterChildExposeHandler(GtkWidget* widget); // Overridden from NativeWidget: - virtual void SetCreateParams(const CreateParams& params) OVERRIDE; + virtual void InitNativeWidget(const CreateParams& params) OVERRIDE; virtual Widget* GetWidget() OVERRIDE; virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE; virtual void* GetNativeWindowProperty(const char* name) OVERRIDE; @@ -309,6 +276,8 @@ class WidgetGtk : public Widget, // Overridden from internal::InputMethodDelegate virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; + void SetCreateParams(const CreateParams& params); + // This is called only when the window is transparent. CHROMEGTK_CALLBACK_1(WidgetGtk, gboolean, OnWindowPaint, GdkEventExpose*); @@ -321,7 +290,7 @@ class WidgetGtk : public Widget, static Window* GetWindowImpl(GtkWidget* widget); // Creates the GtkWidget. - void CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds); + void CreateGtkWidget(const CreateParams& params); // Invoked from create widget to enable the various bits needed for a // transparent background. This is only invoked if MakeTransparent has been @@ -329,8 +298,7 @@ class WidgetGtk : public Widget, void ConfigureWidgetForTransparentBackground(GtkWidget* parent); // Invoked from create widget to enable the various bits needed for a - // window which doesn't receive events. This is only invoked if - // MakeIgnoreEvents has been invoked. + // window which doesn't receive events. void ConfigureWidgetForIgnoreEvents(); // A utility function to draw a transparent background onto the |widget|. @@ -340,8 +308,6 @@ class WidgetGtk : public Widget, // A delegate implementation that handles events received here. internal::NativeWidgetDelegate* delegate_; - const Type type_; - // Our native views. If we're a window/popup, then widget_ is the window and // window_contents_ is a GtkFixed. If we're not a window/popup, then widget_ // and window_contents_ point to the same GtkFixed. @@ -353,6 +319,9 @@ class WidgetGtk : public Widget, // popup that such GtkWidgets are parented to. static GtkWidget* null_parent_; + // True if the widget is a child of some other widget. + bool child_; + // The TooltipManager. // WARNING: RootView's destructor calls into the TooltipManager. As such, this // must be destroyed AFTER root_view_. @@ -369,7 +338,9 @@ class WidgetGtk : public Widget, // See description above make_transparent for details. bool transparent_; - // See description above MakeIgnoreEvents for details. + // Makes the window pass all events through to any windows behind it. + // Set during SetCreateParams before the widget is created. The actual work of + // making the window ignore events is done by ConfigureWidgetForIgnoreEvents. bool ignore_events_; // See note in DropObserver for details on this. diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index edecafb..4748c43 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -194,17 +194,6 @@ void WidgetWin::ClearAccessibilityViewEvent(View* view) { //////////////////////////////////////////////////////////////////////////////// // WidgetWin, Widget implementation: -void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) { - Widget::Init(parent, bounds); - - // Create the window. - WindowImpl::Init(parent, bounds); -} - -void WidgetWin::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { - Init(parent->GetNativeView(), bounds); -} - gfx::NativeView WidgetWin::GetNativeView() const { return WindowImpl::hwnd(); } @@ -234,59 +223,13 @@ void WidgetWin::ViewHierarchyChanged(bool is_add, View* parent, //////////////////////////////////////////////////////////////////////////////// // WidgetWin, NativeWidget implementation: -void WidgetWin::SetCreateParams(const CreateParams& params) { - DCHECK(!GetNativeView()); - - // Set non-style attributes. - delete_on_destroy_ = params.delete_on_destroy; - - DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; - DWORD ex_style = 0; - DWORD class_style = CS_DBLCLKS; - - // Set type-independent style attributes. - if (params.child) - style |= WS_CHILD | WS_VISIBLE; - 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) - ex_style |= WS_EX_LAYERED; - if (params.has_dropshadow) { - class_style |= (base::win::GetVersion() < base::win::VERSION_XP) ? - 0 : CS_DROPSHADOW; - } - - // Set type-dependent style attributes. - switch (params.type) { - case CreateParams::TYPE_WINDOW: - case CreateParams::TYPE_CONTROL: - break; - case CreateParams::TYPE_POPUP: - style |= WS_POPUP; - ex_style |= WS_EX_TOOLWINDOW; - break; - case CreateParams::TYPE_MENU: - style |= WS_POPUP; - is_mouse_button_pressed_ = - ((GetKeyState(VK_LBUTTON) & 0x80) || - (GetKeyState(VK_RBUTTON) & 0x80) || - (GetKeyState(VK_MBUTTON) & 0x80) || - (GetKeyState(VK_XBUTTON1) & 0x80) || - (GetKeyState(VK_XBUTTON2) & 0x80)); - break; - default: - NOTREACHED(); - } +void WidgetWin::InitNativeWidget(const Widget::CreateParams& params) { + SetCreateParams(params); - set_initial_class_style(class_style); - set_window_style(style); - set_window_ex_style(ex_style); + // Create the window. + gfx::NativeView parent = params.parent_widget ? + params.parent_widget->GetNativeView() : params.parent; + WindowImpl::Init(parent, params.bounds); } Widget* WidgetWin::GetWidget() { @@ -1059,6 +1002,59 @@ void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, } } +void WidgetWin::SetCreateParams(const CreateParams& params) { + // Set non-style attributes. + delete_on_destroy_ = params.delete_on_destroy; + + DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; + DWORD ex_style = 0; + DWORD class_style = CS_DBLCLKS; + + // Set type-independent style attributes. + if (params.child) + style |= WS_CHILD | WS_VISIBLE; + 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) + ex_style |= WS_EX_LAYERED; + if (params.has_dropshadow) { + class_style |= (base::win::GetVersion() < base::win::VERSION_XP) ? + 0 : CS_DROPSHADOW; + } + + // Set type-dependent style attributes. + switch (params.type) { + case CreateParams::TYPE_WINDOW: + case CreateParams::TYPE_CONTROL: + break; + case CreateParams::TYPE_POPUP: + style |= WS_POPUP; + ex_style |= WS_EX_TOOLWINDOW; + break; + case CreateParams::TYPE_MENU: + style |= WS_POPUP; + is_mouse_button_pressed_ = + ((GetKeyState(VK_LBUTTON) & 0x80) || + (GetKeyState(VK_RBUTTON) & 0x80) || + (GetKeyState(VK_MBUTTON) & 0x80) || + (GetKeyState(VK_XBUTTON1) & 0x80) || + (GetKeyState(VK_XBUTTON2) & 0x80)); + break; + default: + NOTREACHED(); + } + + set_initial_class_style(class_style); + set_window_style(window_style() | style); + set_window_ex_style(window_ex_style() | ex_style); +} + void WidgetWin::RedrawInvalidRect() { if (!use_layered_buffer_) { RECT r = { 0, 0, 0, 0 }; @@ -1123,10 +1119,8 @@ void WidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) { // Widget, public: // static -Widget* Widget::CreateWidget(const CreateParams& params) { - WidgetWin* widget = new WidgetWin; - widget->SetCreateParams(params); - return widget; +Widget* Widget::CreateWidget() { + return new WidgetWin; } // static diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index 5f92a1f..5b25f2f 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -114,8 +114,6 @@ class WidgetWin : public ui::WindowImpl, void ClearAccessibilityViewEvent(View* view); // Overridden from Widget: - virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds) OVERRIDE; - virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds) OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator) OVERRIDE; @@ -193,7 +191,7 @@ class WidgetWin : public ui::WindowImpl, } // Overridden from NativeWidget: - virtual void SetCreateParams(const Widget::CreateParams& params) OVERRIDE; + virtual void InitNativeWidget(const Widget::CreateParams& params) OVERRIDE; virtual Widget* GetWidget() OVERRIDE; virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE; virtual void* GetNativeWindowProperty(const char* name) OVERRIDE; @@ -424,6 +422,8 @@ class WidgetWin : public ui::WindowImpl, static void PostProcessActivateMessage(WidgetWin* widget, int activation_state); + void SetCreateParams(const Widget::CreateParams& params); + // Synchronously paints the invalid contents of the Widget. void RedrawInvalidRect(); diff --git a/views/widget/widget_win_unittest.cc b/views/widget/widget_win_unittest.cc index ecf89cb..2014194 100644 --- a/views/widget/widget_win_unittest.cc +++ b/views/widget/widget_win_unittest.cc @@ -43,12 +43,12 @@ class WidgetWinTest : public testing::Test { WidgetWin* WidgetWinTest::CreateWidgetWin() { - scoped_ptr<WidgetWin> widget(new WidgetWin()); + scoped_ptr<Widget> widget(Widget::CreateWidget()); Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); params.delete_on_destroy = false; - widget->SetCreateParams(params); - widget->Init(NULL, gfx::Rect(50, 50, 650, 650)); - return widget.release(); + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); + return static_cast<WidgetWin*>(widget.release()->native_widget()); } TEST_F(WidgetWinTest, ZoomWindow) { diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index 1cd519a..a982ac6 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -408,8 +408,7 @@ void WindowGtk::FrameTypeChanged() { // WindowGtk, protected: WindowGtk::WindowGtk(WindowDelegate* window_delegate) - : WidgetGtk(TYPE_WINDOW), - Window(window_delegate), + : Window(window_delegate), ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)), window_state_(GDK_WINDOW_STATE_WITHDRAWN), window_closed_(false) { @@ -420,7 +419,10 @@ WindowGtk::WindowGtk(WindowDelegate* window_delegate) void WindowGtk::InitWindow(GtkWindow* parent, const gfx::Rect& bounds) { if (parent) make_transient_to_parent(); - WidgetGtk::Init(GTK_WIDGET(parent), bounds); + Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW); + params.parent = GTK_WIDGET(parent); + params.bounds = bounds; + GetWidget()->Init(params); delegate_->OnNativeWindowCreated(bounds); g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event", diff --git a/views/window/window_win.cc b/views/window/window_win.cc index 1fb97ac..9b92e7e7 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -242,10 +242,12 @@ WindowWin::~WindowWin() { Window* Window::CreateChromeWindow(gfx::NativeWindow parent, const gfx::Rect& bounds, WindowDelegate* window_delegate) { - WindowWin* window = new WindowWin(window_delegate); - window->GetWindow()->non_client_view()->SetFrameView( - window->CreateFrameViewForWindow()); - window->Init(parent, bounds); + Window* window = new WindowWin(window_delegate); + window->non_client_view()->SetFrameView(window->CreateFrameViewForWindow()); + Widget::CreateParams params(Widget::WindowCreateParams()); + params.parent = parent; + params.bounds = bounds; + window->AsWidget()->Init(params); return window; } @@ -321,20 +323,6 @@ WindowWin::WindowWin(WindowDelegate* window_delegate) set_window_ex_style(0); } -void WindowWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) { - if (window_style() == 0) - set_window_style(CalculateWindowStyle()); - if (window_ex_style() == 0) - set_window_ex_style(CalculateWindowExStyle()); - - GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, - &last_work_area_); - - WidgetWin::Init(parent, bounds); - - delegate_->OnNativeWindowCreated(bounds); -} - gfx::Insets WindowWin::GetClientAreaInsets() const { // Returning an empty Insets object causes the default handling in // WidgetWin::OnNCCalcSize() to be invoked. @@ -369,6 +357,20 @@ int WindowWin::GetShowState() const { /////////////////////////////////////////////////////////////////////////////// // WindowWin, WidgetWin overrides: +void WindowWin::InitNativeWidget(const Widget::CreateParams& params) { + if (window_style() == 0) + set_window_style(CalculateWindowStyle()); + if (window_ex_style() == 0) + set_window_ex_style(CalculateWindowExStyle()); + + GetMonitorAndRects(params.bounds.ToRECT(), &last_monitor_, + &last_monitor_rect_, &last_work_area_); + + WidgetWin::InitNativeWidget(params); + + delegate_->OnNativeWindowCreated(params.bounds); +} + void WindowWin::OnActivateApp(BOOL active, DWORD thread_id) { if (!active && thread_id != GetCurrentThreadId()) { // Another application was activated, we should reset any state that diff --git a/views/window/window_win.h b/views/window/window_win.h index a0c3981..3bcf1d0 100644 --- a/views/window/window_win.h +++ b/views/window/window_win.h @@ -72,12 +72,6 @@ class WindowWin : public WidgetWin, // Constructs the WindowWin. |window_delegate| cannot be NULL. explicit WindowWin(WindowDelegate* window_delegate); - // Create the Window. - // If parent is NULL, this WindowWin is top level on the desktop. - // If |bounds| is empty, the view is queried for its preferred size and - // centered on screen. - virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds) OVERRIDE; - // Returns the insets of the client area relative to the non-client area of // the window. Override this function instead of OnNCCalcSize, which is // crazily complicated. @@ -91,6 +85,7 @@ class WindowWin : public WidgetWin, virtual int GetShowState() const; // Overridden from WidgetWin: + virtual void InitNativeWidget(const Widget::CreateParams& params) OVERRIDE; virtual void OnActivateApp(BOOL active, DWORD thread_id) OVERRIDE; virtual LRESULT OnAppCommand(HWND window, short app_command, |