Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: chrome/browser/ui/views/first_run_bubble.cc

Issue 1411423014: Ensure that the first run bubble displays as an inactive bubble window which ensures that it does n… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add the observer on the root view of the widget Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 }
sky 2015/11/10 22:45:26 What about if FirstBubbleCloser is destroyed becau
ananta 2015/11/10 23:00:12 Done.
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_->GetWidget()->GetRootView()->AddPreTargetHandler(this);
121 }
122
123 void FirstRunBubble::FirstRunBubbleCloser::RemoveKeyboardEventObserver() {
124 DCHECK(target_view_);
125 target_view_->GetWidget()->GetRootView()->RemovePreTargetHandler(this);
126 target_view_ = nullptr;
127 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/first_run_bubble.h ('k') | chrome/browser/ui/views/first_run_bubble_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698