Chromium Code Reviews| 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/confirm_bubble_views.h" | 5 #include "chrome/browser/ui/views/confirm_bubble_views.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/confirm_bubble.h" | 7 #include "chrome/browser/ui/confirm_bubble.h" |
| 8 #include "chrome/browser/ui/confirm_bubble_model.h" | 8 #include "chrome/browser/ui/confirm_bubble_model.h" |
| 9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/image/image.h" | 11 #include "ui/gfx/image/image.h" |
| 12 #include "ui/views/controls/button/image_button.h" | 12 #include "ui/views/controls/button/image_button.h" |
| 13 #include "ui/views/controls/button/text_button.h" | 13 #include "ui/views/controls/button/text_button.h" |
| 14 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 15 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/controls/link.h" | 16 #include "ui/views/controls/link.h" |
| 17 #include "ui/views/layout/grid_layout.h" | 17 #include "ui/views/layout/grid_layout.h" |
| 18 #include "ui/views/layout/layout_constants.h" | 18 #include "ui/views/layout/layout_constants.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Maximum width for the message field. We will wrap the message text when its | 23 // Maximum width for the message field. We will wrap the message text when its |
| 24 // width is wider than this. | 24 // width is wider than this. |
| 25 const int kMaxMessageWidth = 400; | 25 const int kMaxMessageWidth = 400; |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 ConfirmBubbleViews::ConfirmBubbleViews(const gfx::Point& anchor_point, | 29 ConfirmBubbleViews::ConfirmBubbleViews(gfx::NativeView parent, |
| 30 const gfx::Point& anchor_point, | |
| 30 ConfirmBubbleModel* model) | 31 ConfirmBubbleModel* model) |
| 31 : BubbleDelegateView(NULL, views::BubbleBorder::NONE), | 32 : BubbleDelegateView(NULL, views::BubbleBorder::NONE), |
| 32 anchor_point_(anchor_point), | |
| 33 model_(model) { | 33 model_(model) { |
| 34 DCHECK(model); | 34 DCHECK(model); |
| 35 set_anchor_point(anchor_point); | |
| 36 set_parent_window(parent); | |
|
James Cook
2013/01/24 22:57:52
This is the core change that fixes the crash.
| |
| 35 } | 37 } |
| 36 | 38 |
| 37 ConfirmBubbleViews::~ConfirmBubbleViews() { | 39 ConfirmBubbleViews::~ConfirmBubbleViews() { |
| 38 } | 40 } |
| 39 | 41 |
| 40 void ConfirmBubbleViews::ButtonPressed(views::Button* sender, | 42 void ConfirmBubbleViews::ButtonPressed(views::Button* sender, |
| 41 const ui::Event& event) { | 43 const ui::Event& event) { |
| 42 if (sender->tag() == ConfirmBubbleModel::BUTTON_OK) | 44 if (sender->tag() == ConfirmBubbleModel::BUTTON_OK) |
| 43 model_->Accept(); | 45 model_->Accept(); |
| 44 else if (sender->tag() == ConfirmBubbleModel::BUTTON_CANCEL) | 46 else if (sender->tag() == ConfirmBubbleModel::BUTTON_CANCEL) |
| 45 model_->Cancel(); | 47 model_->Cancel(); |
| 46 GetWidget()->Close(); | 48 GetWidget()->Close(); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void ConfirmBubbleViews::LinkClicked(views::Link* source, int event_flags) { | 51 void ConfirmBubbleViews::LinkClicked(views::Link* source, int event_flags) { |
| 50 model_->LinkClicked(); | 52 model_->LinkClicked(); |
| 51 } | 53 } |
| 52 | 54 |
| 53 gfx::Rect ConfirmBubbleViews::GetAnchorRect() { | 55 gfx::Rect ConfirmBubbleViews::GetAnchorRect() { |
| 54 return gfx::Rect(anchor_point_, gfx::Size()); | 56 return gfx::Rect(anchor_point(), gfx::Size()); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void ConfirmBubbleViews::Init() { | 59 void ConfirmBubbleViews::Init() { |
| 58 views::GridLayout* layout = new views::GridLayout(this); | 60 views::GridLayout* layout = new views::GridLayout(this); |
| 59 SetLayoutManager(layout); | 61 SetLayoutManager(layout); |
| 60 | 62 |
| 61 // Add the icon, the title label and the close button to the first row. | 63 // Add the icon, the title label and the close button to the first row. |
| 62 views::ColumnSet* cs = layout->AddColumnSet(0); | 64 views::ColumnSet* cs = layout->AddColumnSet(0); |
| 63 cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, | 65 cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, |
| 64 views::GridLayout::USE_PREF, 0, 0); | 66 views::GridLayout::USE_PREF, 0, 0); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 layout->AddView(cancel_button); | 154 layout->AddView(cancel_button); |
| 153 } | 155 } |
| 154 } | 156 } |
| 155 } | 157 } |
| 156 | 158 |
| 157 namespace chrome { | 159 namespace chrome { |
| 158 | 160 |
| 159 void ShowConfirmBubble(gfx::NativeView view, | 161 void ShowConfirmBubble(gfx::NativeView view, |
| 160 const gfx::Point& origin, | 162 const gfx::Point& origin, |
| 161 ConfirmBubbleModel* model) { | 163 ConfirmBubbleModel* model) { |
| 162 ConfirmBubbleViews* bubble = new ConfirmBubbleViews(origin, model); | 164 ConfirmBubbleViews* bubble = new ConfirmBubbleViews(view, origin, model); |
| 163 views::BubbleDelegateView::CreateBubble(bubble); | 165 views::BubbleDelegateView::CreateBubble(bubble); |
| 164 bubble->Show(); | 166 bubble->Show(); |
| 165 } | 167 } |
| 166 | 168 |
| 167 } // namespace chrome | 169 } // namespace chrome |
| OLD | NEW |