Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h" | |
| 6 | |
| 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/fullscreen/fullscreen_controller.h" | |
| 11 #include "content/public/browser/notification_source.h" | |
| 12 #include "ui/gfx/geometry/rect.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // The bubble's padding from the screen edge, used in fullscreen. | |
| 17 const int kFullscreenPaddingEnd = 20; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 ManagedFullScreenBubbleDelegateView::ManagedFullScreenBubbleDelegateView( | |
| 22 views::View* anchor_view, | |
| 23 content::WebContents* web_contents) | |
| 24 : BubbleDelegateView(anchor_view, | |
| 25 anchor_view ? views::BubbleBorder::TOP_RIGHT | |
| 26 : views::BubbleBorder::NONE) { | |
| 27 // Register accelerator key F11. | |
| 28 AddAccelerator(ui::Accelerator(ui::VKEY_F11, ui::EF_NONE)); | |
| 29 | |
| 30 // Add observer to close the bubble if the fullscreen state changes. | |
| 31 if (web_contents) { | |
|
vasilii
2014/12/18 16:16:22
Can it be NULL?
Pritam Nikam
2014/12/19 09:16:54
I don't think it can be NULL in practical cases, h
| |
| 32 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
| 33 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 34 content::Source<FullscreenController>( | |
| 35 browser->fullscreen_controller())); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 ManagedFullScreenBubbleDelegateView::~ManagedFullScreenBubbleDelegateView() { | |
| 40 } | |
| 41 | |
| 42 void ManagedFullScreenBubbleDelegateView::Observe( | |
| 43 int type, | |
| 44 const content::NotificationSource& source, | |
| 45 const content::NotificationDetails& details) { | |
| 46 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); | |
| 47 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | |
| 48 Close(); | |
| 49 } | |
| 50 | |
| 51 void ManagedFullScreenBubbleDelegateView::AdjustForFullscreen( | |
| 52 const gfx::Rect& screen_bounds) { | |
| 53 if (GetAnchorView()) | |
| 54 return; | |
| 55 | |
| 56 const int bubble_half_width = width() / 2; | |
| 57 const int x_pos = | |
| 58 base::i18n::IsRTL() | |
| 59 ? screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd | |
| 60 : screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; | |
| 61 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | |
| 62 } | |
| 63 | |
| 64 bool ManagedFullScreenBubbleDelegateView::AcceleratorPressed( | |
| 65 const ui::Accelerator& accelerator) { | |
| 66 if (accelerator.key_code() == ui::VKEY_F11) { | |
| 67 Close(); | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 return BubbleDelegateView::AcceleratorPressed(accelerator); | |
| 72 } | |
| 73 | |
| 74 void ManagedFullScreenBubbleDelegateView::Close() { | |
| 75 GetWidget()->Close(); | |
| 76 } | |
| OLD | NEW |