diff options
-rw-r--r-- | chrome/browser/views/bookmark_bubble_view.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bubble_view.h | 2 | ||||
-rw-r--r-- | chrome/browser/views/first_run_bubble.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/first_run_bubble.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.cc | 138 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.h | 39 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 7 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_star_toggle.cc | 6 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 |
9 files changed, 121 insertions, 83 deletions
diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc index 71fd4f1..94eea8b 100644 --- a/chrome/browser/views/bookmark_bubble_view.cc +++ b/chrome/browser/views/bookmark_bubble_view.cc @@ -111,7 +111,7 @@ void BookmarkBubbleView::RecentlyUsedFoldersModel::RemoveNode( BookmarkBubbleView* BookmarkBubbleView::bubble_ = NULL; // static -void BookmarkBubbleView::Show(HWND parent, +void BookmarkBubbleView::Show(views::Window* parent, const gfx::Rect& bounds, InfoBubbleDelegate* delegate, Profile* profile, diff --git a/chrome/browser/views/bookmark_bubble_view.h b/chrome/browser/views/bookmark_bubble_view.h index 76b3a27..a6e032a2 100644 --- a/chrome/browser/views/bookmark_bubble_view.h +++ b/chrome/browser/views/bookmark_bubble_view.h @@ -33,7 +33,7 @@ class BookmarkBubbleView : public views::View, public views::ComboBox::Listener, public InfoBubbleDelegate { public: - static void Show(HWND parent, + static void Show(views::Window* window, const gfx::Rect& bounds, InfoBubbleDelegate* delegate, Profile* profile, diff --git a/chrome/browser/views/first_run_bubble.cc b/chrome/browser/views/first_run_bubble.cc index 38dffbf..7dedfd3 100644 --- a/chrome/browser/views/first_run_bubble.cc +++ b/chrome/browser/views/first_run_bubble.cc @@ -347,7 +347,7 @@ void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble, } // static -FirstRunBubble* FirstRunBubble::Show(Profile* profile, HWND parent_hwnd, +FirstRunBubble* FirstRunBubble::Show(Profile* profile, views::Window* parent, const gfx::Rect& position_relative_to, bool use_OEM_bubble) { FirstRunBubble* window = new FirstRunBubble(); @@ -358,7 +358,7 @@ FirstRunBubble* FirstRunBubble::Show(Profile* profile, HWND parent_hwnd, view = new FirstRunBubbleView(window, profile); window->SetDelegate(window); window->set_view(view); - window->Init(parent_hwnd, position_relative_to, view); + window->Init(parent, position_relative_to, view); window->ShowWindow(SW_SHOW); views::FocusManager* focus_manager = views::FocusManager::GetFocusManager(window->GetNativeView()); diff --git a/chrome/browser/views/first_run_bubble.h b/chrome/browser/views/first_run_bubble.h index 598362b..8da8d04 100644 --- a/chrome/browser/views/first_run_bubble.h +++ b/chrome/browser/views/first_run_bubble.h @@ -14,7 +14,7 @@ class Profile; class FirstRunBubble : public InfoBubble, public InfoBubbleDelegate { public: - static FirstRunBubble* Show(Profile* profile, HWND parent_hwnd, + static FirstRunBubble* Show(Profile* profile, views::Window* window, const gfx::Rect& position_relative_to, bool use_OEM_bubble); @@ -32,8 +32,10 @@ class FirstRunBubble : public InfoBubble, void set_view(FirstRunBubbleViewBase* view) { view_ = view; } +#if defined(OS_WIN) // Overridden from InfoBubble: virtual void OnActivate(UINT action, BOOL minimized, HWND window); +#endif // InfoBubbleDelegate. virtual void InfoBubbleClosing(InfoBubble* info_bubble, diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc index 6fdda8e..2f7091f 100644 --- a/chrome/browser/views/info_bubble.cc +++ b/chrome/browser/views/info_bubble.cc @@ -7,8 +7,6 @@ #include "app/gfx/canvas.h" #include "app/gfx/path.h" #include "app/resource_bundle.h" -#include "app/win_util.h" -#include "base/win_util.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/views/frame/browser_view.h" #include "chrome/common/notification_service.h" @@ -17,6 +15,11 @@ #include "views/widget/root_view.h" #include "views/window/window.h" +#if defined(OS_WIN) +#include "app/win_util.h" +#include "base/win_util.h" +#endif + using views::View; // All sizes are in pixels. @@ -68,21 +71,29 @@ static const int kMinimumAlpha = 72; // InfoBubble ----------------------------------------------------------------- // static -InfoBubble* InfoBubble::Show(HWND parent_hwnd, +InfoBubble* InfoBubble::Show(views::Window* parent, const gfx::Rect& position_relative_to, views::View* content, InfoBubbleDelegate* delegate) { InfoBubble* window = new InfoBubble(); - window->Init(parent_hwnd, position_relative_to, content); + window->Init(parent, position_relative_to, content); // Set the delegate before we show, on the off chance the delegate is needed // during showing. window->delegate_ = delegate; +#if defined(OS_WIN) window->ShowWindow(SW_SHOW); +#else + NOTREACHED(); +#endif return window; } InfoBubble::InfoBubble() - : delegate_(NULL), + : +#if defined(OS_LINUX) + WidgetGtk(TYPE_POPUP), +#endif + delegate_(NULL), parent_(NULL), content_view_(NULL), closed_(false) { @@ -91,14 +102,10 @@ InfoBubble::InfoBubble() InfoBubble::~InfoBubble() { } -void InfoBubble::Init(HWND parent_hwnd, +void InfoBubble::Init(views::Window* parent, const gfx::Rect& position_relative_to, views::View* content) { - HWND owning_frame_hwnd = GetAncestor(parent_hwnd, GA_ROOTOWNER); - BrowserView* browser_view = - BrowserView::GetBrowserViewForHWND(owning_frame_hwnd); - DCHECK(browser_view); - parent_ = browser_view->frame()->GetWindow(); + parent_ = parent; parent_->DisableInactiveRendering(); if (kInfoBubbleCornerTopLeft == NULL) { @@ -111,45 +118,54 @@ void InfoBubble::Init(HWND parent_hwnd, kInfoBubbleCornerBottomRight = ResourceBundle::GetSharedInstance() .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_RIGHT); } +#if defined(OS_WIN) set_window_style(WS_POPUP | WS_CLIPCHILDREN); set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW); // Because we're going to change the alpha value of the layered window we // don't want to use the offscreen buffer provided by WidgetWin. SetUseLayeredBuffer(false); - content_view_ = CreateContentView(content); - gfx::Rect bounds = content_view_-> - CalculateWindowBounds(parent_hwnd, position_relative_to); set_initial_class_style( (win_util::GetWinVersion() < win_util::WINVERSION_XP) ? 0 : CS_DROPSHADOW); +#endif + content_view_ = CreateContentView(content); + gfx::Rect bounds = + content_view_->CalculateWindowBoundsAndAjust(position_relative_to); - WidgetWin::Init(parent_hwnd, bounds, true); +#if defined(OS_WIN) + WidgetWin::Init(parent->GetNativeWindow(), bounds, true); +#endif SetContentsView(content_view_); // The preferred size may differ when parented. Ask for the bounds again // and if they differ reset the bounds. - gfx::Rect parented_bounds = content_view_-> - CalculateWindowBounds(parent_hwnd, position_relative_to); + gfx::Rect parented_bounds = + content_view_->CalculateWindowBoundsAndAjust(position_relative_to); if (bounds != parented_bounds) { +#if defined(OS_WIN) SetWindowPos(NULL, parented_bounds.x(), parented_bounds.y(), parented_bounds.width(), parented_bounds.height(), SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER); // Invoke ChangeSize, otherwise layered window isn't updated correctly. ChangeSize(0, CSize(parented_bounds.width(), parented_bounds.height())); +#else + NOTIMPLEMENTED(); +#endif } +#if defined(OS_WIN) // Register the Escape accelerator for closing. views::FocusManager* focus_manager = views::FocusManager::GetFocusManager(GetNativeView()); focus_manager->RegisterAccelerator(views::Accelerator(VK_ESCAPE, false, false, false), this); - // Set initial alpha value of the layered window. SetLayeredWindowAttributes(GetNativeView(), RGB(0xFF, 0xFF, 0xFF), kMinimumAlpha, LWA_ALPHA); +#endif NotificationService::current()->Notify( NotificationType::INFO_BUBBLE_CREATED, @@ -165,6 +181,7 @@ void InfoBubble::Close() { } void InfoBubble::AnimationProgressed(const Animation* animation) { +#if defined(OS_WIN) int alpha = static_cast<int>(static_cast<double> (fade_animation_->GetCurrentValue() * (255.0 - kMinimumAlpha) + kMinimumAlpha)); @@ -175,10 +192,10 @@ void InfoBubble::AnimationProgressed(const Animation* animation) { LWA_ALPHA); // Don't need to invoke paint as SetLayeredWindowAttributes handles that for // us. +#endif } bool InfoBubble::AcceleratorPressed(const views::Accelerator& accelerator) { - DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); if (!delegate_ || delegate_->CloseOnEscape()) { Close(true); return true; @@ -186,10 +203,7 @@ bool InfoBubble::AcceleratorPressed(const views::Accelerator& accelerator) { return false; } -void InfoBubble::OnSize(UINT param, const CSize& size) { - SetWindowRgn(content_view_->GetMask(size), TRUE); -} - +#if defined(OS_WIN) void InfoBubble::OnActivate(UINT action, BOOL minimized, HWND window) { // The popup should close when it is deactivated. if (action == WA_INACTIVE && !closed_) { @@ -200,6 +214,13 @@ void InfoBubble::OnActivate(UINT action, BOOL minimized, HWND window) { } } +void InfoBubble::OnSize(UINT param, const CSize& size) { + gfx::Path path; + content_view_->GetMask(gfx::Size(size.cx, size.cy), &path); + SetWindowRgn(path.CreateHRGN(), TRUE); +} +#endif + InfoBubble::ContentView* InfoBubble::CreateContentView(View* content) { return new ContentView(content, this); } @@ -212,7 +233,11 @@ void InfoBubble::Close(bool closed_by_escape) { if (delegate_) delegate_->InfoBubbleClosing(this, closed_by_escape); closed_ = true; +#if defined(OS_WIN) WidgetWin::Close(); +#else + WidgetGtk::Close(); +#endif } // ContentView ---------------------------------------------------------------- @@ -227,11 +252,14 @@ InfoBubble::ContentView::ContentView(views::View* content, InfoBubble* host) AddChildView(content); } -gfx::Rect InfoBubble::ContentView::CalculateWindowBounds( - HWND parent_hwnd, +gfx::Rect InfoBubble::ContentView::CalculateWindowBoundsAndAjust( const gfx::Rect& position_relative_to) { +#if defined(OS_WIN) gfx::Rect monitor_bounds = win_util::GetMonitorBoundsForRect( position_relative_to); +#else + gfx::Rect monitor_bounds; +#endif // Calculate the bounds using TOP_LEFT (the default). gfx::Rect window_bounds = CalculateWindowBounds(position_relative_to); if (monitor_bounds.IsEmpty() || monitor_bounds.Contains(window_bounds)) @@ -276,12 +304,10 @@ void InfoBubble::ContentView::Layout() { content->SetBounds(x, y, content_width, content_height); } -HRGN InfoBubble::ContentView::GetMask(const CSize &size) { - gfx::Path mask; - +void InfoBubble::ContentView::GetMask(const gfx::Size& size, gfx::Path* mask) { // Redefine the window visible region so that our dropshadows look right. - SkScalar width = SkIntToScalar(size.cx); - SkScalar height = SkIntToScalar(size.cy); + SkScalar width = SkIntToScalar(size.width()); + SkScalar height = SkIntToScalar(size.height()); SkScalar arrow_size = SkIntToScalar(kArrowSize); SkScalar arrow_x = SkIntToScalar( (IsLeft() ? kArrowXOffset : width - kArrowXOffset) - 1); @@ -289,53 +315,51 @@ HRGN InfoBubble::ContentView::GetMask(const CSize &size) { if (IsTop()) { // Top left corner. - mask.moveTo(0, arrow_size + corner_size - 1); - mask.lineTo(corner_size - 1, arrow_size); + mask->moveTo(0, arrow_size + corner_size - 1); + mask->lineTo(corner_size - 1, arrow_size); // Draw the arrow and the notch of the arrow. - mask.lineTo(arrow_x - arrow_size, arrow_size); - mask.lineTo(arrow_x, 0); - mask.lineTo(arrow_x + 3, 0); - mask.lineTo(arrow_x + arrow_size + 3, arrow_size); + mask->lineTo(arrow_x - arrow_size, arrow_size); + mask->lineTo(arrow_x, 0); + mask->lineTo(arrow_x + 3, 0); + mask->lineTo(arrow_x + arrow_size + 3, arrow_size); // Top right corner. - mask.lineTo(width - corner_size + 1, arrow_size); - mask.lineTo(width, arrow_size + corner_size - 1); + mask->lineTo(width - corner_size + 1, arrow_size); + mask->lineTo(width, arrow_size + corner_size - 1); // Bottom right corner. - mask.lineTo(width, height - corner_size); - mask.lineTo(width - corner_size, height); + mask->lineTo(width, height - corner_size); + mask->lineTo(width - corner_size, height); // Bottom left corner. - mask.lineTo(corner_size, height); - mask.lineTo(0, height - corner_size); + mask->lineTo(corner_size, height); + mask->lineTo(0, height - corner_size); } else { // Top left corner. - mask.moveTo(0, corner_size - 1); - mask.lineTo(corner_size - 1, 0); + mask->moveTo(0, corner_size - 1); + mask->lineTo(corner_size - 1, 0); // Top right corner. - mask.lineTo(width - corner_size + 1, 0); - mask.lineTo(width, corner_size - 1); + mask->lineTo(width - corner_size + 1, 0); + mask->lineTo(width, corner_size - 1); // Bottom right corner. - mask.lineTo(width, height - corner_size - arrow_size); - mask.lineTo(width - corner_size, height - arrow_size); + mask->lineTo(width, height - corner_size - arrow_size); + mask->lineTo(width - corner_size, height - arrow_size); // Draw the arrow and the notch of the arrow. - mask.lineTo(arrow_x + arrow_size + 2, height - arrow_size); - mask.lineTo(arrow_x + 2, height); - mask.lineTo(arrow_x + 1, height); - mask.lineTo(arrow_x - arrow_size + 1, height - arrow_size); + mask->lineTo(arrow_x + arrow_size + 2, height - arrow_size); + mask->lineTo(arrow_x + 2, height); + mask->lineTo(arrow_x + 1, height); + mask->lineTo(arrow_x - arrow_size + 1, height - arrow_size); // Bottom left corner. - mask.lineTo(corner_size, height - arrow_size); - mask.lineTo(0, height - corner_size - arrow_size); + mask->lineTo(corner_size, height - arrow_size); + mask->lineTo(0, height - corner_size - arrow_size); } - mask.close(); - - return mask.CreateHRGN(); + mask->close(); } void InfoBubble::ContentView::Paint(gfx::Canvas* canvas) { diff --git a/chrome/browser/views/info_bubble.h b/chrome/browser/views/info_bubble.h index 2b94ba6..42e36fb 100644 --- a/chrome/browser/views/info_bubble.h +++ b/chrome/browser/views/info_bubble.h @@ -7,7 +7,12 @@ #include "app/slide_animation.h" #include "views/view.h" + +#if defined(OS_WIN) #include "views/widget/widget_win.h" +#elif defined(OS_LINUX) +#include "views/widget/widget_gtk.h" +#endif // InfoBubble is used to display an arbitrary view above all other windows. // Think of InfoBubble as a tooltip that allows you to embed an arbitrary view @@ -19,10 +24,15 @@ // content typically shouldn't have any additional margins around the view. class InfoBubble; + namespace views { class Window; } +namespace gfx { +class Path; +} + class InfoBubbleDelegate { public: // Called when the InfoBubble is closing and is about to be deleted. @@ -35,10 +45,16 @@ class InfoBubbleDelegate { virtual bool CloseOnEscape() = 0; }; -class InfoBubble : public views::WidgetWin, - public AnimationDelegate { +// TODO: this code is ifdef-tastic. It might be cleaner to refactor the +// WidgetFoo subclass into a separate class that calls into InfoBubble. +// That way InfoBubble has no (or very few) ifdefs. +#if defined(OS_WIN) +class InfoBubble : public views::WidgetWin, public AnimationDelegate { +#else +class InfoBubble : public views::WidgetGtk, public AnimationDelegate { +#endif public: - // Shows the InfoBubble. The InfoBubble is parented to parent_hwnd, contains + // Shows the InfoBubble. The InfoBubble is parented to parent, contains // the View content and positioned relative to the screen position // position_relative_to. Show takes ownership of content and deletes the // created InfoBubble when another window is activated. You can explicitly @@ -46,7 +62,7 @@ class InfoBubble : public views::WidgetWin, // to be notified when the InfoBubble is closed and to prevent the InfoBubble // from being closed when the Escape key is pressed (which is the default // behavior if there is no delegate). - static InfoBubble* Show(HWND parent_hwnd, + static InfoBubble* Show(views::Window* parent, const gfx::Rect& position_relative_to, views::View* content, InfoBubbleDelegate* delegate); @@ -55,18 +71,20 @@ class InfoBubble : public views::WidgetWin, virtual ~InfoBubble(); // Creates the InfoBubble. - void Init(HWND parent_hwnd, + void Init(views::Window* parent, const gfx::Rect& position_relative_to, views::View* content); // Sets the delegate for that InfoBubble. void SetDelegate(InfoBubbleDelegate* delegate) { delegate_ = delegate; } +#if defined(OS_WIN) // The InfoBubble is automatically closed when it loses activation status. virtual void OnActivate(UINT action, BOOL minimized, HWND window); // Return our rounded window shape. virtual void OnSize(UINT param, const CSize& size); +#endif // Overridden to notify the owning ChromeFrame the bubble is closing. virtual void Close(); @@ -78,7 +96,6 @@ class InfoBubble : public views::WidgetWin, virtual void AnimationProgressed(const Animation* animation); protected: - // InfoBubble::CreateContentView() creates one of these. ContentView houses // the supplied content as its only child view, renders the arrow/border of // the bubble and sizes the content. @@ -100,11 +117,9 @@ class InfoBubble : public views::WidgetWin, // Returns the bounds for the window to contain this view. // - // This invokes the method of the same name that doesn't take an HWND, if - // the returned bounds don't fit on the monitor containing parent_hwnd, - // the arrow edge is adjusted. - virtual gfx::Rect CalculateWindowBounds( - HWND parent_hwnd, + // This invokes CalculateWindowBounds, if the returned bounds don't fit on + // the monitor containing position_relative_to, the arrow edge is adjusted. + virtual gfx::Rect CalculateWindowBoundsAndAjust( const gfx::Rect& position_relative_to); // Sets the edge the arrow is rendered at. @@ -118,7 +133,7 @@ class InfoBubble : public views::WidgetWin, virtual void Layout(); // Return the mask for the content view. - HRGN GetMask(const CSize& size); + void GetMask(const gfx::Size& size, gfx::Path* mask); // Paints the background and arrow appropriately. virtual void Paint(gfx::Canvas* canvas); diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index 20836d9..a2331f2 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -967,9 +967,7 @@ void LocationBarView::ShowFirstRunBubbleInternal(bool use_OEM_bubble) { if (UILayoutIsRightToLeft()) bounds.set_x(location.x() - 20); - FirstRunBubble::Show(profile_, - location_entry_view_->GetRootView()->GetWidget()->GetNativeView(), - bounds, use_OEM_bubble); + FirstRunBubble::Show(profile_, GetWindow(), bounds, use_OEM_bubble); } // LocationBarImageView--------------------------------------------------------- @@ -1037,8 +1035,7 @@ void LocationBarView::LocationBarImageView::ShowInfoBubbleImpl( label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); label->SizeToFit(0); DCHECK(info_bubble_ == NULL); - info_bubble_ = InfoBubble::Show(GetRootView()->GetWidget()->GetNativeView(), - bounds, label, this); + info_bubble_ = InfoBubble::Show(GetWindow(), bounds, label, this); show_info_bubble_task_ = NULL; } diff --git a/chrome/browser/views/toolbar_star_toggle.cc b/chrome/browser/views/toolbar_star_toggle.cc index 330bb6c..e9440e4 100644 --- a/chrome/browser/views/toolbar_star_toggle.cc +++ b/chrome/browser/views/toolbar_star_toggle.cc @@ -42,10 +42,8 @@ void ToolbarStarToggle::ShowStarBubble(const GURL& url, bool newly_bookmarked) { // of the star. gfx::Rect star_bounds(star_location.x() + 1, star_location.y(), width(), height()); - HWND parent_hwnd = - reinterpret_cast<HWND>(host_->browser()->window()->GetNativeHandle()); - BookmarkBubbleView::Show(parent_hwnd, star_bounds, this, host_->profile(), - url, newly_bookmarked); + BookmarkBubbleView::Show(host_->GetWindow(), star_bounds, this, + host_->profile(), url, newly_bookmarked); } bool ToolbarStarToggle::OnMousePressed(const views::MouseEvent& e) { diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index ebd8257..b44bb19 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1621,6 +1621,8 @@ ['include', '^browser/dock_info.h'], ['include', '^browser/views/frame/browser_frame_gtk.cc'], ['include', '^browser/views/frame/browser_frame_gtk.h'], + ['include', '^browser/views/info_bubble.cc'], + ['include', '^browser/views/info_bubble.h'], ['include', '^browser/views/tabs/dragged_tab_view.cc'], ['include', '^browser/views/tabs/dragged_tab_view.h'], ['include', '^browser/views/tabs/tab.cc'], |