Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view .h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view .h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 11 #include "chrome/browser/ui/layout_constants.h" | 11 #include "chrome/browser/ui/layout_constants.h" |
| 12 #include "content/public/browser/notification_source.h" | 12 #include "content/public/browser/notification_source.h" |
| 13 #include "content/public/browser/render_view_host.h" | |
| 13 #include "ui/base/material_design/material_design_controller.h" | 14 #include "ui/base/material_design/material_design_controller.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 15 | 16 |
| 17 LocationBarBubbleDelegateView::WebContentMouseHandler::WebContentMouseHandler( | |
| 18 LocationBarBubbleDelegateView* bubble, | |
| 19 content::WebContents* web_contents) | |
| 20 : bubble_(bubble), web_contents_(web_contents) { | |
| 21 DCHECK(bubble_); | |
| 22 DCHECK(web_contents_); | |
| 23 event_monitor_ = views::EventMonitor::CreateWindowMonitor( | |
| 24 this, web_contents_->GetTopLevelNativeWindow()); | |
| 25 } | |
| 26 | |
| 27 LocationBarBubbleDelegateView::WebContentMouseHandler:: | |
| 28 ~WebContentMouseHandler() {} | |
| 29 | |
| 30 void LocationBarBubbleDelegateView::WebContentMouseHandler::OnKeyEvent( | |
| 31 ui::KeyEvent* event) { | |
| 32 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | |
|
Peter Kasting
2016/06/13 20:27:24
Nit: Can just inline into the line below
hcarmona
2016/06/13 20:49:03
Done.
| |
| 33 if ((event->key_code() == ui::VKEY_ESCAPE || | |
| 34 rvh->IsFocusedElementEditable()) && | |
| 35 event->type() == ui::ET_KEY_PRESSED) | |
| 36 bubble_->CloseBubble(); | |
| 37 } | |
| 38 | |
| 39 void LocationBarBubbleDelegateView::WebContentMouseHandler::OnMouseEvent( | |
| 40 ui::MouseEvent* event) { | |
| 41 if (event->type() == ui::ET_MOUSE_PRESSED) | |
| 42 bubble_->CloseBubble(); | |
| 43 } | |
| 44 | |
| 45 void LocationBarBubbleDelegateView::WebContentMouseHandler::OnTouchEvent( | |
| 46 ui::TouchEvent* event) { | |
| 47 if (event->type() == ui::ET_TOUCH_PRESSED) | |
| 48 bubble_->CloseBubble(); | |
| 49 } | |
| 50 | |
| 16 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( | 51 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( |
| 17 views::View* anchor_view, | 52 views::View* anchor_view, |
| 18 content::WebContents* web_contents) | 53 content::WebContents* web_contents) |
| 19 : BubbleDialogDelegateView(anchor_view, | 54 : BubbleDialogDelegateView(anchor_view, |
| 20 anchor_view ? views::BubbleBorder::TOP_RIGHT | 55 anchor_view ? views::BubbleBorder::TOP_RIGHT |
| 21 : views::BubbleBorder::NONE) { | 56 : views::BubbleBorder::NONE) { |
| 22 // Add observer to close the bubble if the fullscreen state changes. | 57 // Add observer to close the bubble if the fullscreen state changes. |
| 23 if (web_contents) { | 58 if (web_contents) { |
| 24 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 59 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 25 registrar_.Add( | 60 registrar_.Add( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 if (GetAnchorView()) | 103 if (GetAnchorView()) |
| 69 return; | 104 return; |
| 70 | 105 |
| 71 const int kBubblePaddingFromScreenEdge = 20; | 106 const int kBubblePaddingFromScreenEdge = 20; |
| 72 int horizontal_offset = width() / 2 + kBubblePaddingFromScreenEdge; | 107 int horizontal_offset = width() / 2 + kBubblePaddingFromScreenEdge; |
| 73 const int x_pos = base::i18n::IsRTL() | 108 const int x_pos = base::i18n::IsRTL() |
| 74 ? (screen_bounds.x() + horizontal_offset) | 109 ? (screen_bounds.x() + horizontal_offset) |
| 75 : (screen_bounds.right() - horizontal_offset); | 110 : (screen_bounds.right() - horizontal_offset); |
| 76 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 111 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
| 77 } | 112 } |
| OLD | NEW |