| OLD | NEW |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #endif | 65 #endif |
| 66 | 66 |
| 67 chromeos::BalloonViewImpl* GetBalloonViewOf(const Balloon* balloon) { | 67 chromeos::BalloonViewImpl* GetBalloonViewOf(const Balloon* balloon) { |
| 68 return static_cast<chromeos::BalloonViewImpl*>(balloon->view()); | 68 return static_cast<chromeos::BalloonViewImpl*>(balloon->view()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // A Widget that covers entire ScrollView's viewport. Without this, all | 71 // A Widget that covers entire ScrollView's viewport. Without this, all |
| 72 // renderer's native gtk widgets are moved one by one via | 72 // renderer's native gtk widgets are moved one by one via |
| 73 // View::VisibleBoundsInRootChanged() notification, which makes scrolling not | 73 // View::VisibleBoundsInRootChanged() notification, which makes scrolling not |
| 74 // smooth. | 74 // smooth. |
| 75 // TODO: this should subclass Widget and not WidgetGtk. | 75 class ViewportWidget : public views::Widget { |
| 76 class ViewportWidget : public views::WidgetGtk { | |
| 77 public: | 76 public: |
| 78 explicit ViewportWidget(chromeos::NotificationPanel* panel) | 77 explicit ViewportWidget(chromeos::NotificationPanel* panel) |
| 79 : panel_(panel), | 78 : panel_(panel), |
| 80 pointer_inside_panel_(false) { | 79 pointer_inside_panel_(false) { |
| 81 } | 80 } |
| 82 | 81 |
| 83 void UpdateControl() { | 82 void UpdateControl() { |
| 84 if (pointer_inside_panel_) | 83 if (pointer_inside_panel_) |
| 85 panel_->OnMouseMotion(last_point_); | 84 panel_->OnMouseMotion(last_point_); |
| 86 } | 85 } |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 417 |
| 419 NotificationPanel::~NotificationPanel() { | 418 NotificationPanel::~NotificationPanel() { |
| 420 Hide(); | 419 Hide(); |
| 421 } | 420 } |
| 422 | 421 |
| 423 //////////////////////////////////////////////////////////////////////////////// | 422 //////////////////////////////////////////////////////////////////////////////// |
| 424 // NottificationPanel public. | 423 // NottificationPanel public. |
| 425 | 424 |
| 426 void NotificationPanel::Show() { | 425 void NotificationPanel::Show() { |
| 427 if (!panel_widget_) { | 426 if (!panel_widget_) { |
| 428 panel_widget_ = views::Widget::CreateWidget(); | 427 panel_widget_ = new views::Widget; |
| 429 // TODO(oshima): Using window because Popup widget behaves weird | 428 // TODO(oshima): Using window because Popup widget behaves weird |
| 430 // when resizing. This needs to be investigated. | 429 // when resizing. This needs to be investigated. |
| 431 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 430 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
| 432 // Enable double buffering because the panel has both pure views | 431 // Enable double buffering because the panel has both pure views |
| 433 // control and native controls (scroll bar). | 432 // control and native controls (scroll bar). |
| 434 params.double_buffer = true; | 433 params.double_buffer = true; |
| 435 | 434 |
| 436 gfx::Rect bounds = GetPreferredBounds(); | 435 gfx::Rect bounds = GetPreferredBounds(); |
| 437 bounds = bounds.Union(min_bounds_); | 436 bounds = bounds.Union(min_bounds_); |
| 438 params.bounds = bounds; | 437 params.bounds = bounds; |
| 439 panel_widget_->Init(params); | 438 panel_widget_->Init(params); |
| 440 // Set minimum bounds so that it can grow freely. | 439 // Set minimum bounds so that it can grow freely. |
| 441 gtk_widget_set_size_request(GTK_WIDGET(panel_widget_->GetNativeView()), | 440 gtk_widget_set_size_request(GTK_WIDGET(panel_widget_->GetNativeView()), |
| 442 min_bounds_.width(), min_bounds_.height()); | 441 min_bounds_.width(), min_bounds_.height()); |
| 443 | 442 |
| 444 views::NativeViewHost* native = new views::NativeViewHost(); | 443 views::NativeViewHost* native = new views::NativeViewHost(); |
| 445 scroll_view_->SetContents(native); | 444 scroll_view_->SetContents(native); |
| 446 | 445 |
| 447 panel_widget_->SetContentsView(scroll_view_.get()); | 446 panel_widget_->SetContentsView(scroll_view_.get()); |
| 448 | 447 |
| 449 // Add the view port after scroll_view is attached to the panel widget. | 448 // Add the view port after scroll_view is attached to the panel widget. |
| 450 ViewportWidget* widget = new ViewportWidget(this); | 449 ViewportWidget* viewport_widget = new ViewportWidget(this); |
| 451 container_host_ = widget; | 450 container_host_ = viewport_widget; |
| 452 container_host_->Init( | 451 container_host_->Init( |
| 453 views::Widget::InitParams(views::Widget::InitParams::TYPE_CONTROL)); | 452 views::Widget::InitParams(views::Widget::InitParams::TYPE_CONTROL)); |
| 454 container_host_->SetContentsView(balloon_container_.get()); | 453 container_host_->SetContentsView(balloon_container_.get()); |
| 455 // The window_contents_ is onwed by the Widget. Increase ref count | 454 // The window_contents_ is onwed by the Widget. Increase ref count |
| 456 // so that window_contents does not get deleted when detached. | 455 // so that window_contents does not get deleted when detached. |
| 457 g_object_ref(widget->window_contents()); | 456 g_object_ref(viewport_widget->GetNativeView()); |
| 458 native->Attach(widget->window_contents()); | 457 native->Attach(viewport_widget->GetNativeView()); |
| 459 | 458 |
| 460 UnregisterNotification(); | 459 UnregisterNotification(); |
| 461 panel_controller_.reset( | 460 panel_controller_.reset( |
| 462 new PanelController(this, GTK_WINDOW(panel_widget_->GetNativeView()))); | 461 new PanelController(this, GTK_WINDOW(panel_widget_->GetNativeView()))); |
| 463 panel_controller_->Init(false /* don't focus when opened */, | 462 panel_controller_->Init(false /* don't focus when opened */, |
| 464 gfx::Rect(0, 0, kBalloonMinWidth, 1), 0, | 463 gfx::Rect(0, 0, kBalloonMinWidth, 1), 0, |
| 465 WM_IPC_PANEL_USER_RESIZE_VERTICALLY); | 464 WM_IPC_PANEL_USER_RESIZE_VERTICALLY); |
| 466 registrar_.Add(this, NotificationType::PANEL_STATE_CHANGED, | 465 registrar_.Add(this, NotificationType::PANEL_STATE_CHANGED, |
| 467 Source<PanelController>(panel_controller_.get())); | 466 Source<PanelController>(panel_controller_.get())); |
| 468 } | 467 } |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 &origin); | 857 &origin); |
| 859 return rect.Contains(gfx::Rect(origin, view->size())); | 858 return rect.Contains(gfx::Rect(origin, view->size())); |
| 860 } | 859 } |
| 861 | 860 |
| 862 | 861 |
| 863 bool NotificationPanelTester::IsActive(const BalloonViewImpl* view) const { | 862 bool NotificationPanelTester::IsActive(const BalloonViewImpl* view) const { |
| 864 return panel_->active_ == view; | 863 return panel_->active_ == view; |
| 865 } | 864 } |
| 866 | 865 |
| 867 } // namespace chromeos | 866 } // namespace chromeos |
| OLD | NEW |