| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/first_run_bubble.h" | 5 #include "chrome/browser/ui/views/first_run_bubble.h" |
| 6 | 6 |
| 7 #include "chrome/browser/first_run/first_run.h" | 7 #include "chrome/browser/first_run/first_run.h" |
| 8 #include "chrome/browser/search_engines/template_url_service_factory.h" | 8 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/chrome_pages.h" | 10 #include "chrome/browser/ui/chrome_pages.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/search_engines/util.h" | 12 #include "components/search_engines/util.h" |
| 13 #include "ui/aura/window.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/controls/link.h" | 17 #include "ui/views/controls/link.h" |
| 17 #include "ui/views/layout/grid_layout.h" | 18 #include "ui/views/layout/grid_layout.h" |
| 18 #include "ui/views/layout/layout_constants.h" | 19 #include "ui/views/layout/layout_constants.h" |
| 19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 const int kAnchorVerticalInset = 5; | 23 const int kAnchorVerticalInset = 5; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 GetWidget()->Close(); | 97 GetWidget()->Close(); |
| 97 if (browser_) | 98 if (browser_) |
| 98 chrome::ShowSearchEngineSettings(browser_); | 99 chrome::ShowSearchEngineSettings(browser_); |
| 99 } | 100 } |
| 100 | 101 |
| 101 FirstRunBubble::FirstRunBubbleCloser::FirstRunBubbleCloser( | 102 FirstRunBubble::FirstRunBubbleCloser::FirstRunBubbleCloser( |
| 102 FirstRunBubble* bubble, | 103 FirstRunBubble* bubble, |
| 103 views::View* anchor_view) | 104 views::View* anchor_view) |
| 104 : bubble_(bubble), | 105 : bubble_(bubble), |
| 105 anchor_widget_(anchor_view->GetWidget()) { | 106 anchor_widget_(anchor_view->GetWidget()) { |
| 106 AddKeyboardEventObserver(); | 107 AddEventObservers(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 FirstRunBubble::FirstRunBubbleCloser::~FirstRunBubbleCloser() { | 110 FirstRunBubble::FirstRunBubbleCloser::~FirstRunBubbleCloser() { |
| 110 if (anchor_widget_) | 111 if (anchor_widget_) |
| 111 RemoveKeyboardEventObserver(); | 112 RemoveEventObservers(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void FirstRunBubble::FirstRunBubbleCloser::OnKeyEvent(ui::KeyEvent* event) { | 115 void FirstRunBubble::FirstRunBubbleCloser::OnKeyEvent(ui::KeyEvent* event) { |
| 116 CloseBubble(); |
| 117 } |
| 118 |
| 119 void FirstRunBubble::FirstRunBubbleCloser::OnMouseEvent( |
| 120 ui::MouseEvent* event) { |
| 121 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 122 CloseBubble(); |
| 123 } |
| 124 |
| 125 void FirstRunBubble::FirstRunBubbleCloser::OnGestureEvent( |
| 126 ui::GestureEvent* event) { |
| 127 if (event->type() == ui::ET_GESTURE_TAP || |
| 128 event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 129 CloseBubble(); |
| 130 } |
| 131 } |
| 132 |
| 133 void FirstRunBubble::FirstRunBubbleCloser::AddEventObservers() { |
| 134 anchor_widget_->GetNativeView()->AddPreTargetHandler(this); |
| 135 } |
| 136 |
| 137 void FirstRunBubble::FirstRunBubbleCloser::RemoveEventObservers() { |
| 138 DCHECK(anchor_widget_); |
| 139 anchor_widget_->GetNativeView()->RemovePreTargetHandler(this); |
| 140 anchor_widget_ = nullptr; |
| 141 } |
| 142 |
| 143 void FirstRunBubble::FirstRunBubbleCloser::CloseBubble() { |
| 115 if (!anchor_widget_) | 144 if (!anchor_widget_) |
| 116 return; | 145 return; |
| 117 | 146 |
| 118 RemoveKeyboardEventObserver(); | 147 RemoveEventObservers(); |
| 119 DCHECK(bubble_); | 148 DCHECK(bubble_); |
| 120 bubble_->GetWidget()->Close(); | 149 bubble_->GetWidget()->Close(); |
| 121 bubble_ = nullptr; | 150 bubble_ = nullptr; |
| 122 } | 151 } |
| 123 | |
| 124 void FirstRunBubble::FirstRunBubbleCloser::AddKeyboardEventObserver() { | |
| 125 anchor_widget_->GetRootView()->AddPreTargetHandler(this); | |
| 126 } | |
| 127 | |
| 128 void FirstRunBubble::FirstRunBubbleCloser::RemoveKeyboardEventObserver() { | |
| 129 DCHECK(anchor_widget_); | |
| 130 anchor_widget_->GetRootView()->RemovePreTargetHandler(this); | |
| 131 anchor_widget_ = nullptr; | |
| 132 } | |
| OLD | NEW |