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

Side by Side Diff: chrome/browser/chromeos/notifications/notification_panel.cc

Issue 6881107: Rework the way Widget::Init works: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Draws the view for the balloons. 5 // Draws the view for the balloons.
6 6
7 #include "chrome/browser/chromeos/notifications/notification_panel.h" 7 #include "chrome/browser/chromeos/notifications/notification_panel.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return static_cast<chromeos::BalloonViewImpl*>(balloon->view()); 66 return static_cast<chromeos::BalloonViewImpl*>(balloon->view());
67 } 67 }
68 68
69 // A WidgetGtk that covers entire ScrollView's viewport. Without this, 69 // A WidgetGtk that covers entire ScrollView's viewport. Without this,
70 // all renderer's native gtk widgets are moved one by one via 70 // all renderer's native gtk widgets are moved one by one via
71 // View::VisibleBoundsInRootChanged() notification, which makes 71 // View::VisibleBoundsInRootChanged() notification, which makes
72 // scrolling not smooth. 72 // scrolling not smooth.
73 class ViewportWidget : public views::WidgetGtk { 73 class ViewportWidget : public views::WidgetGtk {
74 public: 74 public:
75 explicit ViewportWidget(chromeos::NotificationPanel* panel) 75 explicit ViewportWidget(chromeos::NotificationPanel* panel)
76 : WidgetGtk(views::WidgetGtk::TYPE_CHILD), 76 : panel_(panel) {
77 panel_(panel) {
78 } 77 }
79 78
80 void UpdateControl() { 79 void UpdateControl() {
81 if (last_point_.get()) 80 if (last_point_.get())
82 panel_->OnMouseMotion(*last_point_.get()); 81 panel_->OnMouseMotion(*last_point_.get());
83 } 82 }
84 83
85 // views::WidgetGtk overrides. 84 // views::WidgetGtk overrides.
86 virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event) { 85 virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event) {
87 gboolean result = WidgetGtk::OnMotionNotify(widget, event); 86 gboolean result = WidgetGtk::OnMotionNotify(widget, event);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 407
409 NotificationPanel::~NotificationPanel() { 408 NotificationPanel::~NotificationPanel() {
410 Hide(); 409 Hide();
411 } 410 }
412 411
413 //////////////////////////////////////////////////////////////////////////////// 412 ////////////////////////////////////////////////////////////////////////////////
414 // NottificationPanel public. 413 // NottificationPanel public.
415 414
416 void NotificationPanel::Show() { 415 void NotificationPanel::Show() {
417 if (!panel_widget_) { 416 if (!panel_widget_) {
418 // TODO(oshima): Using window because Popup widget behaves weird 417 panel_widget_ = views::Widget::CreateWidget();
419 // when resizing. This needs to be investigated.
420 views::WidgetGtk* widget_gtk =
421 new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW);
422 // Enable double buffering because the panel has both pure views 418 // Enable double buffering because the panel has both pure views
423 // control and native controls (scroll bar). 419 // control and native controls (scroll bar).
424 widget_gtk->EnableDoubleBuffer(true); 420 static_cast<views::WidgetGtk*>(panel_widget_->native_widget())->
425 panel_widget_ = widget_gtk; 421 EnableDoubleBuffer(true);
426 422
427 gfx::Rect bounds = GetPreferredBounds(); 423 gfx::Rect bounds = GetPreferredBounds();
428 bounds = bounds.Union(min_bounds_); 424 bounds = bounds.Union(min_bounds_);
429 panel_widget_->Init(NULL, bounds); 425 views::Widget::CreateParams params(
426 views::Widget::CreateParams::TYPE_WINDOW);
427 params.bounds = bounds;
428 panel_widget_->Init(params);
430 // Set minimum bounds so that it can grow freely. 429 // Set minimum bounds so that it can grow freely.
431 gtk_widget_set_size_request(GTK_WIDGET(panel_widget_->GetNativeView()), 430 gtk_widget_set_size_request(GTK_WIDGET(panel_widget_->GetNativeView()),
432 min_bounds_.width(), min_bounds_.height()); 431 min_bounds_.width(), min_bounds_.height());
433 432
434 views::NativeViewHost* native = new views::NativeViewHost(); 433 views::NativeViewHost* native = new views::NativeViewHost();
435 scroll_view_->SetContents(native); 434 scroll_view_->SetContents(native);
436 435
437 panel_widget_->SetContentsView(scroll_view_.get()); 436 panel_widget_->SetContentsView(scroll_view_.get());
438 437
439 // Add the view port after scroll_view is attached to the panel widget. 438 // Add the view port after scroll_view is attached to the panel widget.
440 ViewportWidget* widget = new ViewportWidget(this); 439 ViewportWidget* widget = new ViewportWidget(this);
441 container_host_ = widget; 440 container_host_ = widget;
442 container_host_->Init(NULL, gfx::Rect()); 441 container_host_->Init(
442 views::Widget::CreateParams(views::Widget::CreateParams::TYPE_CONTROL));
443 container_host_->SetContentsView(balloon_container_.get()); 443 container_host_->SetContentsView(balloon_container_.get());
444 // The window_contents_ is onwed by the WidgetGtk. Increase ref count 444 // The window_contents_ is onwed by the WidgetGtk. Increase ref count
445 // so that window_contents does not get deleted when detached. 445 // so that window_contents does not get deleted when detached.
446 g_object_ref(widget->window_contents()); 446 g_object_ref(widget->window_contents());
447 native->Attach(widget->window_contents()); 447 native->Attach(widget->window_contents());
448 448
449 UnregisterNotification(); 449 UnregisterNotification();
450 panel_controller_.reset( 450 panel_controller_.reset(
451 new PanelController(this, GTK_WINDOW(panel_widget_->GetNativeView()))); 451 new PanelController(this, GTK_WINDOW(panel_widget_->GetNativeView())));
452 panel_controller_->Init(false /* don't focus when opened */, 452 panel_controller_->Init(false /* don't focus when opened */,
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 &origin); 847 &origin);
848 return rect.Contains(gfx::Rect(origin, view->size())); 848 return rect.Contains(gfx::Rect(origin, view->size()));
849 } 849 }
850 850
851 851
852 bool NotificationPanelTester::IsActive(const BalloonViewImpl* view) const { 852 bool NotificationPanelTester::IsActive(const BalloonViewImpl* view) const {
853 return panel_->active_ == view; 853 return panel_->active_ == view;
854 } 854 }
855 855
856 } // namespace chromeos 856 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/notifications/balloon_view.cc ('k') | chrome/browser/chromeos/panels/panel_scroller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698