| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/browser_finder.h" | 7 #include "chrome/browser/ui/browser_finder.h" |
| 8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" | 9 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 11 #include "chrome/browser/ui/views/frame/top_container_view.h" | 11 #include "chrome/browser/ui/views/frame/top_container_view.h" |
| 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 13 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 13 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 14 #include "chrome/browser/ui/views/website_settings/permission_prompt_impl.h" | 14 #include "chrome/browser/ui/views/website_settings/permission_prompt_impl.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "ui/gfx/geometry/point.h" | 16 #include "ui/gfx/geometry/point.h" |
| 17 #include "ui/gfx/geometry/vector2d.h" | 17 #include "ui/gfx/geometry/vector2d.h" |
| 18 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
| 19 | 19 |
| 20 // The Views browser implementation of PermissionPromptImpl's | 20 // The Views browser implementation of PermissionPromptImpl's |
| 21 // anchor methods. Views browsers have a native View to anchor the bubble to, | 21 // anchor methods. Views browsers have a native View to anchor the bubble to, |
| 22 // which these functions provide. | 22 // which these functions provide. |
| 23 | 23 |
| 24 // Left margin for the bubble when anchored to the top of the screen in | 24 // Left margin for the bubble when anchored to the top of the screen in |
| 25 // fullscreen mode. | 25 // fullscreen mode. |
| 26 const int kFullscreenLeftMargin = 40; | 26 const int kFullscreenLeftMargin = 40; |
| 27 | 27 |
| 28 views::View* PermissionPromptImpl::GetAnchorView() { | 28 views::View* PermissionPromptImpl::GetAnchorView() { |
| 29 if (!browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) |
| 30 return nullptr; // Fall back to GetAnchorPoint(). |
| 31 |
| 29 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 32 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
| 30 | 33 return browser_view->GetLocationBarView()->GetSecurityBubbleAnchorView(); |
| 31 if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) | |
| 32 return browser_view->GetLocationBarView() | |
| 33 ->location_icon_view() | |
| 34 ->GetImageView(); | |
| 35 | |
| 36 // Fall back to GetAnchorPoint(). | |
| 37 return nullptr; | |
| 38 } | 34 } |
| 39 | 35 |
| 40 gfx::Point PermissionPromptImpl::GetAnchorPoint() { | 36 gfx::Point PermissionPromptImpl::GetAnchorPoint() { |
| 41 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 37 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
| 42 // Get position in view (taking RTL displays into account). | 38 // Get position in view (taking RTL displays into account). |
| 43 int x_within_browser_view = | 39 int x_within_browser_view = |
| 44 browser_view->GetMirroredXInView(kFullscreenLeftMargin); | 40 browser_view->GetMirroredXInView(kFullscreenLeftMargin); |
| 45 // Get position in screen (taking browser view origin into account, which may | 41 // Get position in screen (taking browser view origin into account, which may |
| 46 // not be 0,0 if there are multiple displays). | 42 // not be 0,0 if there are multiple displays). |
| 47 gfx::Point browser_view_origin = browser_view->GetBoundsInScreen().origin(); | 43 gfx::Point browser_view_origin = browser_view->GetBoundsInScreen().origin(); |
| 48 return browser_view_origin + gfx::Vector2d(x_within_browser_view, 0); | 44 return browser_view_origin + gfx::Vector2d(x_within_browser_view, 0); |
| 49 } | 45 } |
| 50 | 46 |
| 51 views::BubbleBorder::Arrow PermissionPromptImpl::GetAnchorArrow() { | 47 views::BubbleBorder::Arrow PermissionPromptImpl::GetAnchorArrow() { |
| 52 return views::BubbleBorder::TOP_LEFT; | 48 return views::BubbleBorder::TOP_LEFT; |
| 53 } | 49 } |
| 54 | 50 |
| 55 // static | 51 // static |
| 56 std::unique_ptr<PermissionPrompt> PermissionPrompt::Create( | 52 std::unique_ptr<PermissionPrompt> PermissionPrompt::Create( |
| 57 content::WebContents* web_contents) { | 53 content::WebContents* web_contents) { |
| 58 return base::WrapUnique(new PermissionPromptImpl( | 54 return base::WrapUnique(new PermissionPromptImpl( |
| 59 chrome::FindBrowserWithWebContents(web_contents))); | 55 chrome::FindBrowserWithWebContents(web_contents))); |
| 60 } | 56 } |
| OLD | NEW |