Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/views/bubble/bubble.h" // for kBackgroundColor | |
|
msw
2011/10/18 18:39:23
really? this seems wrong, let's not mix bubbles. A
alicet1
2011/10/19 05:02:15
I think you're handling this one already, so I'll
| |
| 9 #include "chrome/browser/first_run/first_run.h" | 10 #include "chrome/browser/first_run/first_run.h" |
| 10 #include "chrome/browser/search_engines/util.h" | 11 #include "chrome/browser/search_engines/util.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "content/browser/user_metrics.h" | 15 #include "content/browser/user_metrics.h" |
| 15 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
| 16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 17 #include "grit/locale_settings.h" | 18 #include "grit/locale_settings.h" |
| 18 #include "grit/theme_resources_standard.h" | 19 #include "grit/theme_resources_standard.h" |
| 19 #include "ui/base/l10n/l10n_font_util.h" | 20 #include "ui/base/l10n/l10n_font_util.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "views/bubble/bubble_view.h" | |
| 22 #include "views/controls/button/image_button.h" | 24 #include "views/controls/button/image_button.h" |
| 23 #include "views/controls/button/text_button.h" | 25 #include "views/controls/button/text_button.h" |
| 24 #include "views/controls/label.h" | 26 #include "views/controls/label.h" |
| 25 #include "views/events/event.h" | 27 #include "views/events/event.h" |
| 26 #include "views/focus/focus_manager.h" | 28 #include "views/focus/focus_manager.h" |
| 27 #include "views/layout/layout_constants.h" | 29 #include "views/layout/layout_constants.h" |
| 30 #if defined(OS_WIN) | |
| 28 #include "views/widget/native_widget_win.h" | 31 #include "views/widget/native_widget_win.h" |
|
msw
2011/10/18 18:39:23
Can we avoid this platform specific include altoge
alicet1
2011/10/19 05:02:15
I'll remove it when I manage to remove the two OS_
| |
| 32 #endif | |
| 29 #include "views/widget/widget.h" | 33 #include "views/widget/widget.h" |
| 30 | |
|
msw
2011/10/18 18:39:23
leave this line there.
alicet1
2011/10/19 05:02:15
Done.
| |
| 31 namespace { | 34 namespace { |
| 32 | 35 |
| 33 // How much extra padding to put around our content over what the Bubble | 36 // How much extra padding to put around our content over what the Bubble |
| 34 // provides. | 37 // provides. |
| 35 const int kBubblePadding = 4; | 38 const int kBubblePadding = 4; |
| 36 | 39 |
| 37 // How much extra padding to put around our content over what the Bubble | 40 // How much extra padding to put around our content over what the Bubble |
| 38 // provides in alternative OEM bubble. | 41 // provides in alternative OEM bubble. |
| 39 const int kOEMBubblePadding = 4; | 42 const int kOEMBubblePadding = 4; |
| 40 | 43 |
| 41 // Padding between parts of strings on the same line (for instance, | |
| 42 // "New!" and "Search from the address bar!" | |
| 43 const int kStringSeparationPadding = 2; | |
| 44 | |
| 45 // Margin around close button. | 44 // Margin around close button. |
| 46 const int kMarginRightOfCloseButton = 7; | 45 const int kMarginRightOfCloseButton = 7; |
| 47 | 46 |
| 47 #if defined(OS_WIN) | |
| 48 // The bubble's HWND is actually owned by the border widget, and it's the border | 48 // The bubble's HWND is actually owned by the border widget, and it's the border |
| 49 // widget that's owned by the frame window the bubble is anchored to. This | 49 // widget that's owned by the frame window the bubble is anchored to. This |
| 50 // function makes the two leaps necessary to go from the bubble contents HWND | 50 // function makes the two leaps necessary to go from the bubble contents HWND |
| 51 // to the frame HWND. | 51 // to the frame HWND. |
| 52 HWND GetLogicalBubbleOwner(HWND bubble_hwnd) { | 52 HWND GetLogicalBubbleOwner(HWND bubble_hwnd) { |
|
msw
2011/10/18 18:39:23
You should eliminate this function (along with Ena
alicet1
2011/10/19 05:02:15
removed this. EnableParent is another one I'm not
| |
| 53 HWND border_widget_hwnd = GetWindow(bubble_hwnd, GW_OWNER); | 53 HWND border_widget_hwnd = GetWindow(bubble_hwnd, GW_OWNER); |
| 54 return GetWindow(border_widget_hwnd, GW_OWNER); | 54 return GetWindow(border_widget_hwnd, GW_OWNER); |
| 55 } | 55 } |
| 56 #endif | |
| 56 | 57 |
| 57 } // namespace | 58 } // namespace |
| 58 | 59 |
| 59 // Base class for implementations of the client view which appears inside the | 60 // Base class for implementations of the client view which appears inside the |
| 60 // first run bubble. It is a dialog-ish view, but is not a true dialog. | 61 // first run bubble. It is a dialog-ish view, but is not a true dialog. |
| 61 class FirstRunBubbleViewBase : public views::View, | 62 class FirstRunBubbleViewBase : public views::View, |
| 62 public views::ButtonListener, | 63 public views::ButtonListener, |
| 63 public views::FocusChangeListener { | 64 public views::FocusChangeListener { |
| 64 public: | 65 public: |
| 65 // Called by FirstRunBubble::Show to request focus for the proper button | 66 virtual views::View* GetInitiallyFocusedView() = 0; |
| 66 // in the FirstRunBubbleView when it is shown. | |
| 67 virtual void BubbleShown() = 0; | |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 // FirstRunBubbleView --------------------------------------------------------- | 69 // FirstRunBubbleView --------------------------------------------------------- |
| 71 | 70 |
| 72 class FirstRunBubbleView : public FirstRunBubbleViewBase { | 71 class FirstRunBubbleView : public FirstRunBubbleViewBase { |
| 73 public: | 72 public: |
| 74 FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile); | 73 FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile); |
| 75 | 74 virtual gfx::Size GetPreferredSize(); |
| 75 virtual views::View* GetInitiallyFocusedView() { return keep_button_; } | |
| 76 private: | 76 private: |
| 77 virtual ~FirstRunBubbleView() {} | 77 virtual ~FirstRunBubbleView(); |
| 78 | |
| 79 // FirstRunBubbleViewBase: | |
| 80 virtual void BubbleShown(); | |
| 81 | 78 |
| 82 // Overridden from View: | 79 // Overridden from View: |
| 83 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | 80 virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| 84 virtual void Layout(); | 81 virtual void Layout(); |
| 85 virtual gfx::Size GetPreferredSize(); | |
| 86 | 82 |
| 87 // FocusChangeListener: | 83 // FocusChangeListener: |
| 88 virtual void FocusWillChange(View* focused_before, View* focused_now); | 84 virtual void FocusWillChange(View* focused_before, View* focused_now); |
| 89 | 85 |
| 90 FirstRunBubble* bubble_window_; | 86 FirstRunBubble* bubble_window_; |
| 91 views::Label* label1_; | 87 views::Label* label1_; |
| 92 views::Label* label2_; | 88 views::Label* label2_; |
| 93 views::Label* label3_; | 89 views::Label* label3_; |
| 90 views::NativeTextButton* keep_button_; | |
| 94 views::NativeTextButton* change_button_; | 91 views::NativeTextButton* change_button_; |
| 95 views::NativeTextButton* keep_button_; | |
| 96 Profile* profile_; | 92 Profile* profile_; |
| 97 | 93 |
| 98 DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleView); | 94 DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleView); |
| 99 }; | 95 }; |
| 100 | 96 |
| 101 FirstRunBubbleView::FirstRunBubbleView(FirstRunBubble* bubble_window, | 97 FirstRunBubbleView::FirstRunBubbleView(FirstRunBubble* bubble_window, |
| 102 Profile* profile) | 98 Profile* profile) |
| 103 : bubble_window_(bubble_window), | 99 : bubble_window_(bubble_window), |
| 104 label1_(NULL), | 100 label1_(NULL), |
| 105 label2_(NULL), | 101 label2_(NULL), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 keep_button_ = new views::NativeTextButton(this, keep_str); | 139 keep_button_ = new views::NativeTextButton(this, keep_str); |
| 144 keep_button_->SetIsDefault(true); | 140 keep_button_->SetIsDefault(true); |
| 145 AddChildView(keep_button_); | 141 AddChildView(keep_button_); |
| 146 | 142 |
| 147 std::wstring change_str = | 143 std::wstring change_str = |
| 148 UTF16ToWide(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE)); | 144 UTF16ToWide(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE)); |
| 149 change_button_ = new views::NativeTextButton(this, change_str); | 145 change_button_ = new views::NativeTextButton(this, change_str); |
| 150 AddChildView(change_button_); | 146 AddChildView(change_button_); |
| 151 } | 147 } |
| 152 | 148 |
| 153 void FirstRunBubbleView::BubbleShown() { | 149 FirstRunBubbleView::~FirstRunBubbleView() { |
| 154 keep_button_->RequestFocus(); | 150 GetFocusManager()->RemoveFocusChangeListener(this); |
| 155 } | 151 } |
| 156 | 152 |
| 157 void FirstRunBubbleView::ButtonPressed(views::Button* sender, | 153 void FirstRunBubbleView::ButtonPressed(views::Button* sender, |
| 158 const views::Event& event) { | 154 const views::Event& event) { |
| 159 UserMetrics::RecordAction(UserMetricsAction("FirstRunBubbleView_Clicked")); | 155 UserMetrics::RecordAction(UserMetricsAction("FirstRunBubbleView_Clicked")); |
| 160 bubble_window_->set_fade_away_on_close(true); | 156 // Fades out. |
| 161 bubble_window_->Close(); | 157 GetWidget()->client_view()->AsBubbleView()->StartFade(false); |
| 162 if (change_button_ == sender) { | 158 if (change_button_ == sender) { |
| 163 UserMetrics::RecordAction( | 159 UserMetrics::RecordAction( |
| 164 UserMetricsAction("FirstRunBubbleView_ChangeButton")); | 160 UserMetricsAction("FirstRunBubbleView_ChangeButton")); |
| 165 | 161 |
| 166 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 162 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 167 if (browser) { | 163 if (browser) { |
| 168 browser->OpenSearchEngineOptionsDialog(); | 164 browser->OpenSearchEngineOptionsDialog(); |
| 169 } | 165 } |
| 170 } | 166 } |
| 167 GetWidget()->Close(); | |
| 171 } | 168 } |
| 172 | 169 |
| 173 void FirstRunBubbleView::Layout() { | 170 void FirstRunBubbleView::Layout() { |
| 174 gfx::Size canvas = GetPreferredSize(); | 171 gfx::Size canvas = GetPreferredSize(); |
| 175 | 172 |
| 176 // The multiline business that follows is dirty hacks to get around | 173 // The multiline business that follows is dirty hacks to get around |
| 177 // bug 1325257. | 174 // bug 1325257. |
| 178 label1_->SetMultiLine(false); | 175 label1_->SetMultiLine(false); |
| 179 gfx::Size pref_size = label1_->GetPreferredSize(); | 176 gfx::Size pref_size = label1_->GetPreferredSize(); |
| 180 label1_->SetMultiLine(true); | 177 label1_->SetMultiLine(true); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 static_cast<views::NativeTextButton*>(focused_now); | 230 static_cast<views::NativeTextButton*>(focused_now); |
| 234 after->SetIsDefault(true); | 231 after->SetIsDefault(true); |
| 235 } | 232 } |
| 236 } | 233 } |
| 237 | 234 |
| 238 // FirstRunOEMBubbleView ------------------------------------------------------ | 235 // FirstRunOEMBubbleView ------------------------------------------------------ |
| 239 | 236 |
| 240 class FirstRunOEMBubbleView : public FirstRunBubbleViewBase { | 237 class FirstRunOEMBubbleView : public FirstRunBubbleViewBase { |
| 241 public: | 238 public: |
| 242 FirstRunOEMBubbleView(FirstRunBubble* bubble_window, Profile* profile); | 239 FirstRunOEMBubbleView(FirstRunBubble* bubble_window, Profile* profile); |
| 240 virtual gfx::Size GetPreferredSize(); | |
| 241 // FirstRunBubbleViewBase: | |
| 242 virtual views::View* GetInitiallyFocusedView() { return this; } | |
| 243 | 243 |
| 244 private: | 244 private: |
| 245 virtual ~FirstRunOEMBubbleView() { } | 245 virtual ~FirstRunOEMBubbleView(); |
| 246 | |
| 247 // FirstRunBubbleViewBase: | |
| 248 virtual void BubbleShown(); | |
| 249 | 246 |
| 250 // Overridden from View: | 247 // Overridden from View: |
| 251 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | 248 virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| 252 virtual void Layout(); | 249 virtual void Layout(); |
| 253 virtual gfx::Size GetPreferredSize(); | |
| 254 | 250 |
| 255 // FocusChangeListener: | 251 // FocusChangeListener: |
| 256 virtual void FocusWillChange(View* focused_before, View* focused_now); | 252 virtual void FocusWillChange(View* focused_before, View* focused_now); |
| 257 | 253 |
| 258 FirstRunBubble* bubble_window_; | 254 FirstRunBubble* bubble_window_; |
| 259 views::Label* label1_; | 255 views::Label* label1_; |
| 260 views::Label* label2_; | 256 views::Label* label2_; |
| 261 views::Label* label3_; | 257 views::Label* label3_; |
| 262 views::ImageButton* close_button_; | 258 views::ImageButton* close_button_; |
| 263 Profile* profile_; | 259 Profile* profile_; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 close_button_->SetImage(views::CustomButton::BS_NORMAL, | 302 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 307 rb.GetBitmapNamed(IDR_CLOSE_BAR)); | 303 rb.GetBitmapNamed(IDR_CLOSE_BAR)); |
| 308 close_button_->SetImage(views::CustomButton::BS_HOT, | 304 close_button_->SetImage(views::CustomButton::BS_HOT, |
| 309 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); | 305 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); |
| 310 close_button_->SetImage(views::CustomButton::BS_PUSHED, | 306 close_button_->SetImage(views::CustomButton::BS_PUSHED, |
| 311 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); | 307 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); |
| 312 | 308 |
| 313 AddChildView(close_button_); | 309 AddChildView(close_button_); |
| 314 } | 310 } |
| 315 | 311 |
| 316 void FirstRunOEMBubbleView::BubbleShown() { | 312 FirstRunOEMBubbleView::~FirstRunOEMBubbleView() { |
| 317 RequestFocus(); | 313 GetFocusManager()->RemoveFocusChangeListener(this); |
| 318 // No button in oem_bubble to request focus. | |
| 319 } | 314 } |
| 320 | 315 |
| 321 void FirstRunOEMBubbleView::ButtonPressed(views::Button* sender, | 316 void FirstRunOEMBubbleView::ButtonPressed(views::Button* sender, |
| 322 const views::Event& event) { | 317 const views::Event& event) { |
| 323 UserMetrics::RecordAction( | 318 UserMetrics::RecordAction( |
| 324 UserMetricsAction("FirstRunOEMBubbleView_Clicked")); | 319 UserMetricsAction("FirstRunOEMBubbleView_Clicked")); |
| 325 bubble_window_->set_fade_away_on_close(true); | 320 GetWidget()->client_view()->AsBubbleView()->StartFade(/*fade_in=*/false); |
| 326 bubble_window_->Close(); | 321 GetWidget()->Close(); |
| 327 } | 322 } |
| 328 | 323 |
| 329 void FirstRunOEMBubbleView::Layout() { | 324 void FirstRunOEMBubbleView::Layout() { |
| 330 gfx::Size canvas = GetPreferredSize(); | 325 gfx::Size canvas = GetPreferredSize(); |
| 331 | 326 |
| 332 // First, draw the close button on the far right. | 327 // First, draw the close button on the far right. |
| 333 gfx::Size sz = close_button_->GetPreferredSize(); | 328 gfx::Size sz = close_button_->GetPreferredSize(); |
| 334 close_button_->SetBounds( | 329 close_button_->SetBounds( |
| 335 canvas.width() - sz.width() - kMarginRightOfCloseButton, | 330 canvas.width() - sz.width() - kMarginRightOfCloseButton, |
| 336 kOEMBubblePadding, sz.width(), sz.height()); | 331 kOEMBubblePadding, sz.width(), sz.height()); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 359 gfx::Size FirstRunOEMBubbleView::GetPreferredSize() { | 354 gfx::Size FirstRunOEMBubbleView::GetPreferredSize() { |
| 360 // Calculate width based on font and text. | 355 // Calculate width based on font and text. |
| 361 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 356 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 362 const gfx::Font& font = rb.GetFont( | 357 const gfx::Font& font = rb.GetFont( |
| 363 ResourceBundle::MediumFont).DeriveFont(3, gfx::Font::BOLD); | 358 ResourceBundle::MediumFont).DeriveFont(3, gfx::Font::BOLD); |
| 364 gfx::Size size = gfx::Size( | 359 gfx::Size size = gfx::Size( |
| 365 ui::GetLocalizedContentsWidthForFont( | 360 ui::GetLocalizedContentsWidthForFont( |
| 366 IDS_FIRSTRUNOEMBUBBLE_DIALOG_WIDTH_CHARS, font), | 361 IDS_FIRSTRUNOEMBUBBLE_DIALOG_WIDTH_CHARS, font), |
| 367 ui::GetLocalizedContentsHeightForFont( | 362 ui::GetLocalizedContentsHeightForFont( |
| 368 IDS_FIRSTRUNOEMBUBBLE_DIALOG_HEIGHT_LINES, font)); | 363 IDS_FIRSTRUNOEMBUBBLE_DIALOG_HEIGHT_LINES, font)); |
| 369 | 364 #if defined(OS_WIN) |
| 370 // WARNING: HACK. Vista and XP calculate font size differently; this means | 365 // WARNING: HACK. Vista and XP calculate font size differently; this means |
| 371 // that a dialog box correctly proportioned for XP will appear too large in | 366 // that a dialog box correctly proportioned for XP will appear too large in |
| 372 // Vista. The correct thing to do is to change font size calculations in | 367 // Vista. The correct thing to do is to change font size calculations in |
| 373 // XP or Vista so that the length of a string is calculated properly. For | 368 // XP or Vista so that the length of a string is calculated properly. For |
| 374 // now, we force Vista to show a correctly-sized box by taking account of | 369 // now, we force Vista to show a correctly-sized box by taking account of |
| 375 // the difference in font size calculation. The coefficient should not be | 370 // the difference in font size calculation. The coefficient should not be |
| 376 // stored in a variable because it's a hack and should go away. | 371 // stored in a variable because it's a hack and should go away. |
| 377 if (views::NativeWidgetWin::IsAeroGlassEnabled()) { | 372 if (views::NativeWidgetWin::IsAeroGlassEnabled()) { |
| 378 size.set_width(static_cast<int>(size.width() * 0.85)); | 373 size.set_width(static_cast<int>(size.width() * 0.85)); |
| 379 size.set_height(static_cast<int>(size.height() * 0.85)); | 374 size.set_height(static_cast<int>(size.height() * 0.85)); |
| 380 } | 375 } |
| 376 #endif | |
| 381 return size; | 377 return size; |
| 382 } | 378 } |
| 383 | 379 |
| 384 void FirstRunOEMBubbleView::FocusWillChange(View* focused_before, | 380 void FirstRunOEMBubbleView::FocusWillChange(View* focused_before, |
| 385 View* focused_now) { | 381 View* focused_now) { |
| 386 // No buttons in oem_bubble to register focus changes. | 382 // No buttons in oem_bubble to register focus changes. |
| 387 } | 383 } |
| 388 | 384 |
| 389 // FirstRunMinimalBubbleView -------------------------------------------------- | 385 // FirstRunMinimalBubbleView -------------------------------------------------- |
| 390 // TODO(mirandac): combine FRBubbles more elegantly. http://crbug.com/41353 | 386 // TODO(mirandac): combine FRBubbles more elegantly. http://crbug.com/41353 |
| 391 | 387 |
| 392 class FirstRunMinimalBubbleView : public FirstRunBubbleViewBase { | 388 class FirstRunMinimalBubbleView : public FirstRunBubbleViewBase { |
| 393 public: | 389 public: |
| 394 FirstRunMinimalBubbleView(FirstRunBubble* bubble_window, Profile* profile); | 390 FirstRunMinimalBubbleView(FirstRunBubble* bubble_window, Profile* profile); |
| 391 virtual gfx::Size GetPreferredSize(); | |
| 392 // FirstRunBubbleViewBase: | |
| 393 virtual views::View* GetInitiallyFocusedView() { return this; } | |
| 395 | 394 |
| 396 private: | 395 private: |
| 397 virtual ~FirstRunMinimalBubbleView() { } | 396 virtual ~FirstRunMinimalBubbleView(); |
| 398 | |
| 399 // FirstRunBubbleViewBase: | |
| 400 virtual void BubbleShown(); | |
| 401 | 397 |
| 402 // Overridden from View: | 398 // Overridden from View: |
| 403 virtual void ButtonPressed(views::Button* sender, | 399 virtual void ButtonPressed(views::Button* sender, |
| 404 const views::Event& event) { } | 400 const views::Event& event) { } |
| 405 virtual void Layout(); | 401 virtual void Layout(); |
| 406 virtual gfx::Size GetPreferredSize(); | |
| 407 | 402 |
| 408 // FocusChangeListener: | 403 // FocusChangeListener: |
| 409 virtual void FocusWillChange(View* focused_before, View* focused_now); | 404 virtual void FocusWillChange(View* focused_before, View* focused_now); |
| 410 | 405 |
| 411 FirstRunBubble* bubble_window_; | 406 FirstRunBubble* bubble_window_; |
| 412 Profile* profile_; | 407 Profile* profile_; |
| 413 views::Label* label1_; | 408 views::Label* label1_; |
| 414 views::Label* label2_; | 409 views::Label* label2_; |
| 415 | 410 |
| 416 DISALLOW_COPY_AND_ASSIGN(FirstRunMinimalBubbleView); | 411 DISALLOW_COPY_AND_ASSIGN(FirstRunMinimalBubbleView); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 439 label2_ = new views::Label( | 434 label2_ = new views::Label( |
| 440 l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT)); | 435 l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT)); |
| 441 label2_->SetMultiLine(true); | 436 label2_->SetMultiLine(true); |
| 442 label2_->SetFont(font); | 437 label2_->SetFont(font); |
| 443 label2_->SetBackgroundColor(Bubble::kBackgroundColor); | 438 label2_->SetBackgroundColor(Bubble::kBackgroundColor); |
| 444 label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 439 label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 445 label2_->SizeToFit(ps.width() - kBubblePadding * 2); | 440 label2_->SizeToFit(ps.width() - kBubblePadding * 2); |
| 446 AddChildView(label2_); | 441 AddChildView(label2_); |
| 447 } | 442 } |
| 448 | 443 |
| 449 void FirstRunMinimalBubbleView::BubbleShown() { | 444 FirstRunMinimalBubbleView::~FirstRunMinimalBubbleView() { |
| 450 RequestFocus(); | 445 GetFocusManager()->RemoveFocusChangeListener(this); |
| 451 } | 446 } |
| 452 | 447 |
| 453 void FirstRunMinimalBubbleView::Layout() { | 448 void FirstRunMinimalBubbleView::Layout() { |
| 454 gfx::Size canvas = GetPreferredSize(); | 449 gfx::Size canvas = GetPreferredSize(); |
| 455 | 450 |
| 456 // See comments in FirstRunOEMBubbleView::Layout explaining this hack. | 451 // See comments in FirstRunOEMBubbleView::Layout explaining this hack. |
| 457 label1_->SetMultiLine(false); | 452 label1_->SetMultiLine(false); |
| 458 gfx::Size pref_size = label1_->GetPreferredSize(); | 453 gfx::Size pref_size = label1_->GetPreferredSize(); |
| 459 label1_->SetMultiLine(true); | 454 label1_->SetMultiLine(true); |
| 460 label1_->SizeToFit(canvas.width() - kBubblePadding * 2); | 455 label1_->SizeToFit(canvas.width() - kBubblePadding * 2); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 479 | 474 |
| 480 void FirstRunMinimalBubbleView::FocusWillChange(View* focused_before, | 475 void FirstRunMinimalBubbleView::FocusWillChange(View* focused_before, |
| 481 View* focused_now) { | 476 View* focused_now) { |
| 482 // No buttons in minimal bubble to register focus changes. | 477 // No buttons in minimal bubble to register focus changes. |
| 483 } | 478 } |
| 484 | 479 |
| 485 | 480 |
| 486 // FirstRunBubble ------------------------------------------------------------- | 481 // FirstRunBubble ------------------------------------------------------------- |
| 487 | 482 |
| 488 // static | 483 // static |
| 489 FirstRunBubble* FirstRunBubble::Show( | 484 views::Widget* FirstRunBubble::Show( |
| 490 Profile* profile, | 485 Profile* profile, |
| 491 views::Widget* parent, | 486 views::Widget* parent, |
| 492 const gfx::Rect& position_relative_to, | 487 const gfx::Rect& position_relative_to, |
| 493 views::BubbleBorder::ArrowLocation arrow_location, | 488 views::BubbleBorder::ArrowLocation arrow_location, |
| 494 FirstRun::BubbleType bubble_type) { | 489 FirstRun::BubbleType bubble_type) { |
| 495 FirstRunBubble* bubble = new FirstRunBubble(); | 490 FirstRunBubble* delegate = |
| 491 new FirstRunBubble(profile, | |
| 492 parent, | |
| 493 position_relative_to, | |
| 494 arrow_location, | |
| 495 bubble_type); | |
| 496 views::Widget* widget = | |
| 497 views::BubbleDelegateView::CreateBubble(delegate, parent); | |
| 498 // StartFade and show. | |
| 499 widget->client_view()->AsBubbleView()->StartFade(/*fade_in=*/true); | |
| 500 return widget; | |
| 501 } | |
| 502 | |
| 503 void FirstRunBubble::Init() { | |
| 496 FirstRunBubbleViewBase* view = NULL; | 504 FirstRunBubbleViewBase* view = NULL; |
| 497 | 505 switch (bubble_type_) { |
| 498 switch (bubble_type) { | |
| 499 case FirstRun::OEM_BUBBLE: | 506 case FirstRun::OEM_BUBBLE: |
| 500 view = new FirstRunOEMBubbleView(bubble, profile); | 507 view = new FirstRunOEMBubbleView(this, profile_); |
| 501 break; | 508 break; |
| 502 case FirstRun::LARGE_BUBBLE: | 509 case FirstRun::LARGE_BUBBLE: |
| 503 view = new FirstRunBubbleView(bubble, profile); | 510 view = new FirstRunBubbleView(this, profile_); |
| 504 break; | 511 break; |
| 505 case FirstRun::MINIMAL_BUBBLE: | 512 case FirstRun::MINIMAL_BUBBLE: |
| 506 view = new FirstRunMinimalBubbleView(bubble, profile); | 513 view = new FirstRunMinimalBubbleView(this, profile_); |
| 507 break; | 514 break; |
| 508 default: | 515 default: |
| 509 NOTREACHED(); | 516 NOTREACHED(); |
| 510 } | 517 } |
| 511 bubble->set_view(view); | 518 AddChildView(view); |
|
msw
2011/10/18 18:39:23
You might need to use a FillLayout to make the chi
alicet1
2011/10/19 05:02:15
Done.
| |
| 512 bubble->InitBubble( | 519 preferred_size_ = view->GetPreferredSize(); |
| 513 parent, position_relative_to, arrow_location, view, bubble); | 520 initially_focused_view_ = view->GetInitiallyFocusedView(); |
| 514 bubble->GetWidget()->GetFocusManager()->AddFocusChangeListener(view); | 521 parent_->GetFocusManager()->AddFocusChangeListener(view); |
| 515 view->BubbleShown(); | |
|
msw
2011/10/18 18:39:23
Do you need to still call BubbleShown?
alicet1
2011/10/19 05:02:15
re-added.
| |
| 516 return bubble; | |
| 517 } | 522 } |
| 518 | 523 |
| 519 FirstRunBubble::FirstRunBubble() | 524 FirstRunBubble::FirstRunBubble( |
| 520 : has_been_activated_(false), | 525 Profile* profile, |
| 521 ALLOW_THIS_IN_INITIALIZER_LIST(enable_window_method_factory_(this)), | 526 views::Widget* parent, |
| 522 view_(NULL) { | 527 const gfx::Rect& position_relative_to, |
| 528 views::BubbleBorder::ArrowLocation arrow_location, | |
| 529 FirstRun::BubbleType bubble_type) | |
| 530 : profile_(profile), | |
| 531 parent_(parent), | |
| 532 position_relative_to_(position_relative_to), | |
| 533 arrow_location_(arrow_location), | |
| 534 bubble_type_(bubble_type), | |
| 535 initially_focused_view_(NULL), | |
| 536 has_been_activated_(false), | |
| 537 ALLOW_THIS_IN_INITIALIZER_LIST(enable_window_method_factory_(this)) { | |
| 523 } | 538 } |
| 524 | 539 |
| 525 FirstRunBubble::~FirstRunBubble() { | 540 FirstRunBubble::~FirstRunBubble() { |
| 526 enable_window_method_factory_.InvalidateWeakPtrs(); | 541 enable_window_method_factory_.InvalidateWeakPtrs(); |
| 527 GetWidget()->GetFocusManager()->RemoveFocusChangeListener(view_); | |
| 528 } | 542 } |
| 529 | 543 |
| 544 gfx::Point FirstRunBubble::GetAnchorPoint() const { | |
| 545 return position_relative_to_.origin(); | |
| 546 } | |
| 547 | |
| 548 gfx::Size FirstRunBubble::GetPreferredSize() { | |
| 549 return preferred_size_; | |
|
msw
2011/10/18 18:39:23
preferred_size_ and this override are unnecessary
alicet1
2011/10/19 05:02:15
Done.
| |
| 550 } | |
| 551 views::View* FirstRunBubble::GetInitiallyFocusedView() { | |
|
msw
2011/10/18 18:39:23
insert a blank line between these function definit
alicet1
2011/10/19 05:02:15
removed
| |
| 552 return initially_focused_view_; | |
| 553 } | |
| 554 | |
| 555 #if !defined(USE_AURA) | |
|
msw
2011/10/18 18:39:23
You've got an OS_WIN block above for GetLogicalBub
alicet1
2011/10/19 05:02:15
Done.
| |
| 530 void FirstRunBubble::EnableParent() { | 556 void FirstRunBubble::EnableParent() { |
|
msw
2011/10/18 18:39:23
This just seems wrong altogether... Can you safely
alicet1
2011/10/19 05:02:15
Got rid of the GetLogicalBubbleOwner, not sure if
| |
| 531 ::EnableWindow(GetParent(), true); | 557 ::EnableWindow(GetParent(), true); |
| 532 // The EnableWindow() call above causes the parent to become active, which | 558 // The EnableWindow() call above causes the parent to become active, which |
| 533 // resets the flag set by Bubble's call to DisableInactiveRendering(), so we | 559 // resets the flag set by Bubble's call to DisableInactiveRendering(), so we |
| 534 // have to call it again before activating the bubble to prevent the parent | 560 // have to call it again before activating the bubble to prevent the parent |
| 535 // window from rendering inactive. | 561 // window from rendering inactive. |
| 536 // TODO(beng): this only works in custom-frame mode, not glass-frame mode. | 562 // TODO(beng): this only works in custom-frame mode, not glass-frame mode. |
| 537 HWND bubble_owner = GetLogicalBubbleOwner(GetNativeView()); | 563 HWND bubble_owner = GetLogicalBubbleOwner(GetNativeView()); |
| 538 views::Widget* parent = views::Widget::GetWidgetForNativeView(bubble_owner); | 564 views::Widget* parent = views::Widget::GetWidgetForNativeView(bubble_owner); |
| 539 if (parent) | 565 if (parent) |
| 540 parent->DisableInactiveRendering(); | 566 parent->DisableInactiveRendering(); |
| 541 // Reactivate the FirstRunBubble so it responds to OnActivate messages. | 567 // Reactivate the FirstRunBubble so it responds to OnActivate messages. |
| 542 SetWindowPos(GetParent(), 0, 0, 0, 0, | 568 SetWindowPos(GetParent(), 0, 0, 0, 0, |
| 543 SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW | SWP_SHOWWINDOW); | 569 SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW | SWP_SHOWWINDOW); |
| 544 } | 570 } |
| 571 #endif | |
| 545 | 572 |
| 546 #if defined(OS_WIN) && !defined(USE_AURA) | 573 #if defined(OS_WIN) && !defined(USE_AURA) |
| 547 void FirstRunBubble::OnActivate(UINT action, BOOL minimized, HWND window) { | 574 void FirstRunBubble::OnActivate(UINT action, BOOL minimized, HWND window) { |
| 548 // Keep the bubble around for kLingerTime milliseconds, to prevent accidental | 575 // Keep the bubble around for kLingerTime milliseconds, to prevent accidental |
| 549 // closure. | 576 // closure. |
| 550 const int kLingerTime = 3000; | 577 const int kLingerTime = 3000; |
| 551 | 578 |
| 552 // We might get re-enabled right before we are closed (sequence is: we get | 579 // We might get re-enabled right before we are closed (sequence is: we get |
| 553 // deactivated, we call close, before we are actually closed we get | 580 // deactivated, we call close, before we are actually closed we get |
| 554 // reactivated). Don't do the disabling of the parent in such cases. | 581 // reactivated). Don't do the disabling of the parent in such cases. |
| 555 if (action == WA_ACTIVE && !has_been_activated_) { | 582 if (action == WA_ACTIVE && !has_been_activated_) { |
| 556 has_been_activated_ = true; | 583 has_been_activated_ = true; |
| 557 | 584 |
| 558 ::EnableWindow(GetParent(), false); | 585 ::EnableWindow(GetParent(), false); |
| 559 | 586 |
| 560 MessageLoop::current()->PostDelayedTask( | 587 MessageLoop::current()->PostDelayedTask( |
| 561 FROM_HERE, | 588 FROM_HERE, |
| 562 base::Bind(&FirstRunBubble::EnableParent, | 589 base::Bind(&FirstRunBubble::EnableParent, |
| 563 enable_window_method_factory_.GetWeakPtr()), | 590 enable_window_method_factory_.GetWeakPtr()), |
| 564 kLingerTime); | 591 kLingerTime); |
| 565 return; | 592 return; |
| 566 } | 593 } |
| 567 | 594 |
| 568 // Keep window from automatically closing until kLingerTime has passed. | 595 // Keep window from automatically closing until kLingerTime has passed. |
| 569 if (::IsWindowEnabled(GetParent())) | 596 if (::IsWindowEnabled(GetParent())) |
| 570 Bubble::OnActivate(action, minimized, window); | 597 Bubble::OnActivate(action, minimized, window); |
| 571 } | 598 } |
| 572 #endif | 599 #endif |
| 573 | 600 |
| 601 #if !defined(USE_AURA) | |
|
msw
2011/10/18 18:39:23
This seems like it won't work in any case...
I thi
alicet1
2011/10/19 05:02:15
updated.
| |
| 574 void FirstRunBubble::BubbleClosing(Bubble* bubble, bool closed_by_escape) { | 602 void FirstRunBubble::BubbleClosing(Bubble* bubble, bool closed_by_escape) { |
| 575 // Make sure our parent window is re-enabled. | 603 // Make sure our parent window is re-enabled. |
| 576 if (!IsWindowEnabled(GetParent())) | 604 if (!IsWindowEnabled(GetParent())) |
| 577 ::EnableWindow(GetParent(), true); | 605 ::EnableWindow(GetParent(), true); |
| 578 } | 606 } |
| 607 #endif | |
| OLD | NEW |