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" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 const int kBottomInset = 7; | 25 const int kBottomInset = 7; |
26 const int kRightInset = 2; | 26 const int kRightInset = 2; |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 // static | 29 // static |
30 FirstRunBubble* FirstRunBubble::ShowBubble(Browser* browser, | 30 FirstRunBubble* FirstRunBubble::ShowBubble(Browser* browser, |
31 views::View* anchor_view) { | 31 views::View* anchor_view) { |
32 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_SHOWN); | 32 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_SHOWN); |
33 | 33 |
34 FirstRunBubble* delegate = new FirstRunBubble(browser, anchor_view); | 34 FirstRunBubble* delegate = new FirstRunBubble(browser, anchor_view); |
35 views::BubbleDelegateView::CreateBubble(delegate)->Show(); | 35 views::BubbleDelegateView::CreateBubble(delegate)->ShowInactive(); |
36 return delegate; | 36 return delegate; |
37 } | 37 } |
38 | 38 |
39 void FirstRunBubble::Init() { | 39 void FirstRunBubble::Init() { |
40 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 40 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
41 const gfx::FontList& original_font_list = | 41 const gfx::FontList& original_font_list = |
42 rb.GetFontList(ui::ResourceBundle::MediumFont); | 42 rb.GetFontList(ui::ResourceBundle::MediumFont); |
43 | 43 |
44 const base::string16 search_engine_name = browser_ ? | 44 const base::string16 search_engine_name = browser_ ? |
45 GetDefaultSearchEngineName( | 45 GetDefaultSearchEngineName( |
(...skipping 27 matching lines...) Expand all Loading... | |
73 layout->StartRow(0, 0); | 73 layout->StartRow(0, 0); |
74 layout->AddView(title); | 74 layout->AddView(title); |
75 layout->AddView(change); | 75 layout->AddView(change); |
76 layout->StartRowWithPadding(0, 0, 0, | 76 layout->StartRowWithPadding(0, 0, 0, |
77 views::kRelatedControlSmallVerticalSpacing); | 77 views::kRelatedControlSmallVerticalSpacing); |
78 layout->AddView(subtext, columns->num_columns(), 1); | 78 layout->AddView(subtext, columns->num_columns(), 1); |
79 } | 79 } |
80 | 80 |
81 FirstRunBubble::FirstRunBubble(Browser* browser, views::View* anchor_view) | 81 FirstRunBubble::FirstRunBubble(Browser* browser, views::View* anchor_view) |
82 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 82 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
83 browser_(browser) { | 83 browser_(browser), |
84 bubble_closer_(this, anchor_view) { | |
84 // Compensate for built-in vertical padding in the anchor view's image. | 85 // Compensate for built-in vertical padding in the anchor view's image. |
85 set_anchor_view_insets( | 86 set_anchor_view_insets( |
86 gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0)); | 87 gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0)); |
87 } | 88 } |
88 | 89 |
89 FirstRunBubble::~FirstRunBubble() { | 90 FirstRunBubble::~FirstRunBubble() { |
90 } | 91 } |
91 | 92 |
92 void FirstRunBubble::LinkClicked(views::Link* source, int event_flags) { | 93 void FirstRunBubble::LinkClicked(views::Link* source, int event_flags) { |
93 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED); | 94 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED); |
94 | 95 |
95 GetWidget()->Close(); | 96 GetWidget()->Close(); |
96 if (browser_) | 97 if (browser_) |
97 chrome::ShowSearchEngineSettings(browser_); | 98 chrome::ShowSearchEngineSettings(browser_); |
98 } | 99 } |
100 | |
101 FirstRunBubble::FirstRunBubbleCloser::FirstRunBubbleCloser( | |
102 FirstRunBubble* bubble, | |
103 views::View* target_view) | |
104 : bubble_(bubble), | |
105 target_view_(target_view) { | |
106 AddKeyboardEventObserver(); | |
107 } | |
108 | |
109 void FirstRunBubble::FirstRunBubbleCloser::OnKeyEvent(ui::KeyEvent* event) { | |
110 if (!target_view_) | |
111 return; | |
112 | |
113 RemoveKeyboardEventObserver(); | |
114 DCHECK(bubble_); | |
115 bubble_->GetWidget()->Close(); | |
116 bubble_ = nullptr; | |
117 } | |
118 | |
119 void FirstRunBubble::FirstRunBubbleCloser::AddKeyboardEventObserver() { | |
120 target_view_->AddPreTargetHandler(this); | |
sky
2015/11/10 22:09:20
Why do you need to add to both target_view_ and th
ananta
2015/11/10 22:35:36
We now add the observer only on the root view of t
| |
121 target_view_->parent()->AddPreTargetHandler(this); | |
122 } | |
123 | |
124 void FirstRunBubble::FirstRunBubbleCloser::RemoveKeyboardEventObserver() { | |
125 DCHECK(target_view_); | |
126 target_view_->RemovePreTargetHandler(this); | |
127 target_view_->parent()->RemovePreTargetHandler(this); | |
128 target_view_ = nullptr; | |
129 } | |
OLD | NEW |