1 // Copyright 2014 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.
5 #include "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
11 #include "content/public/browser/notification_source.h"
12 #include "ui/gfx/geometry/rect.h"
14 ManagedFullScreenBubbleDelegateView::ManagedFullScreenBubbleDelegateView(
15 views::View
* anchor_view
,
16 content::WebContents
* web_contents
)
20 views::BubbleBorder::TOP_RIGHT
: views::BubbleBorder::NONE
) {
21 // Add observer to close the bubble if the fullscreen state changes.
23 Browser
* browser
= chrome::FindBrowserWithWebContents(web_contents
);
25 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED
,
26 content::Source
<FullscreenController
>(
27 browser
->exclusive_access_manager()->fullscreen_controller()));
31 ManagedFullScreenBubbleDelegateView::~ManagedFullScreenBubbleDelegateView() {
34 void ManagedFullScreenBubbleDelegateView::Observe(
36 const content::NotificationSource
& source
,
37 const content::NotificationDetails
& details
) {
38 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED
, type
);
39 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE
);
43 void ManagedFullScreenBubbleDelegateView::Close() {
44 views::Widget
* widget
= GetWidget();
45 if (!widget
->IsClosed())
49 void ManagedFullScreenBubbleDelegateView::AdjustForFullscreen(
50 const gfx::Rect
& screen_bounds
) {
54 const int kBubblePaddingFromScreenEdge
= 20;
55 int bubble_half_width
= width() / 2;
56 const int x_pos
= base::i18n::IsRTL() ?
57 (screen_bounds
.x() + bubble_half_width
+ kBubblePaddingFromScreenEdge
) :
58 (screen_bounds
.right() - bubble_half_width
-
59 kBubblePaddingFromScreenEdge
);
60 SetAnchorRect(gfx::Rect(x_pos
, screen_bounds
.y(), 0, 0));