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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/notifications/balloon_collection_impl.h" 6 7 #include "chrome/browser/notifications/balloon.h" 8 #include "ui/gfx/size.h" 9 10 #if defined(TOOLKIT_VIEWS) 11 #include "chrome/browser/ui/views/notifications/balloon_view.h" 12 #else 13 #include "chrome/browser/ui/gtk/notifications/balloon_view_gtk.h" 14 #endif 15 16 Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification, 17 Profile* profile) { 18 Balloon* balloon = new Balloon(notification, profile, this); 19 20 balloon->set_view(new BalloonViewImpl(this)); 21 gfx::Size size(layout_.min_balloon_width(), layout_.min_balloon_height()); 22 balloon->set_content_size(size); 23 return balloon; 24 } 25 26 int BalloonCollectionImpl::Layout::InterBalloonMargin() const { 27 return 5; 28 } 29 30 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const { 31 return 5; 32 } 33 34 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const { 35 return 5; 36 } 37 38 void BalloonCollectionImpl::PositionBalloons(bool reposition) { 39 PositionBalloonsInternal(reposition); 40 } 41 42 void BalloonCollectionImpl::DidProcessEvent(GdkEvent* event) { 43 switch (event->type) { 44 case GDK_MOTION_NOTIFY: 45 case GDK_LEAVE_NOTIFY: 46 HandleMouseMoveEvent(); 47 break; 48 default: 49 break; 50 } 51 } 52 53 bool BalloonCollectionImpl::IsCursorInBalloonCollection() const { 54 GdkScreen* screen = gdk_screen_get_default(); 55 GdkDisplay* display = gdk_screen_get_display(screen); 56 gint x, y; 57 gdk_display_get_pointer(display, NULL, &x, &y, NULL); 58 gfx::Point cursor(x, y); 59 60 return GetBalloonsBoundingBox().Contains(cursor); 61 } 62 63 void BalloonCollectionImpl::SetPositionPreference( 64 PositionPreference position) { 65 if (position == DEFAULT_POSITION) 66 position = LOWER_RIGHT; 67 68 // All positioning schemes are vertical, and linux 69 // uses the normal screen orientation. 70 if (position == UPPER_RIGHT) 71 layout_.set_placement(Layout::VERTICALLY_FROM_TOP_RIGHT); 72 else if (position == UPPER_LEFT) 73 layout_.set_placement(Layout::VERTICALLY_FROM_TOP_LEFT); 74 else if (position == LOWER_LEFT) 75 layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_LEFT); 76 else if (position == LOWER_RIGHT) 77 layout_.set_placement(Layout::VERTICALLY_FROM_BOTTOM_RIGHT); 78 else 79 NOTREACHED(); 80 81 PositionBalloons(true); 82 } 83 84 // static 85 BalloonCollection* BalloonCollection::Create() { 86 return new BalloonCollectionImpl(); 87 } 88