| 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 "ui/views/examples/bubble_example.h" | 5 #include "ui/views/examples/bubble_example.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/views/bubble/bubble_delegate.h" | 8 #include "ui/views/bubble/bubble_delegate.h" |
| 9 #include "ui/views/controls/button/label_button.h" | 9 #include "ui/views/controls/button/label_button.h" |
| 10 #include "ui/views/controls/label.h" | 10 #include "ui/views/controls/label.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 BubbleExample::BubbleExample() : ExampleBase("Bubble") {} | 66 BubbleExample::BubbleExample() : ExampleBase("Bubble") {} |
| 67 | 67 |
| 68 BubbleExample::~BubbleExample() {} | 68 BubbleExample::~BubbleExample() {} |
| 69 | 69 |
| 70 void BubbleExample::CreateExampleView(View* container) { | 70 void BubbleExample::CreateExampleView(View* container) { |
| 71 PrintStatus("Click with optional modifiers: [Ctrl] for set_arrow(NONE), " | 71 PrintStatus("Click with optional modifiers: [Ctrl] for set_arrow(NONE), " |
| 72 "[Alt] for set_arrow(FLOAT), or [Shift] to reverse the arrow iteration."); | 72 "[Alt] for set_arrow(FLOAT), or [Shift] to reverse the arrow iteration."); |
| 73 container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 10)); | 73 container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 10)); |
| 74 shadow_ = new LabelButton(this, ASCIIToUTF16("Shadow")); | |
| 75 container->AddChildView(shadow_); | |
| 76 no_shadow_ = new LabelButton(this, ASCIIToUTF16("No Shadow")); | 74 no_shadow_ = new LabelButton(this, ASCIIToUTF16("No Shadow")); |
| 77 container->AddChildView(no_shadow_); | 75 container->AddChildView(no_shadow_); |
| 78 big_shadow_ = new LabelButton(this, ASCIIToUTF16("Big Shadow")); | 76 big_shadow_ = new LabelButton(this, ASCIIToUTF16("Big Shadow")); |
| 79 container->AddChildView(big_shadow_); | 77 container->AddChildView(big_shadow_); |
| 80 small_shadow_ = new LabelButton(this, ASCIIToUTF16("Small Shadow")); | 78 small_shadow_ = new LabelButton(this, ASCIIToUTF16("Small Shadow")); |
| 81 container->AddChildView(small_shadow_); | 79 container->AddChildView(small_shadow_); |
| 82 align_to_edge_ = new LabelButton(this, ASCIIToUTF16("Align To Edge")); | 80 align_to_edge_ = new LabelButton(this, ASCIIToUTF16("Align To Edge")); |
| 83 container->AddChildView(align_to_edge_); | 81 container->AddChildView(align_to_edge_); |
| 84 persistent_ = new LabelButton(this, ASCIIToUTF16("Persistent")); | 82 persistent_ = new LabelButton(this, ASCIIToUTF16("Persistent")); |
| 85 container->AddChildView(persistent_); | 83 container->AddChildView(persistent_); |
| 86 fade_in_ = new LabelButton(this, ASCIIToUTF16("Fade In")); | 84 fade_in_ = new LabelButton(this, ASCIIToUTF16("Fade In")); |
| 87 container->AddChildView(fade_in_); | 85 container->AddChildView(fade_in_); |
| 88 } | 86 } |
| 89 | 87 |
| 90 void BubbleExample::ButtonPressed(Button* sender, const ui::Event& event) { | 88 void BubbleExample::ButtonPressed(Button* sender, const ui::Event& event) { |
| 91 static int arrow_index = 0, color_index = 0; | 89 static int arrow_index = 0, color_index = 0; |
| 92 static const int count = arraysize(arrows); | 90 static const int count = arraysize(arrows); |
| 93 arrow_index = (arrow_index + count + (event.IsShiftDown() ? -1 : 1)) % count; | 91 arrow_index = (arrow_index + count + (event.IsShiftDown() ? -1 : 1)) % count; |
| 94 BubbleBorder::Arrow arrow = arrows[arrow_index]; | 92 BubbleBorder::Arrow arrow = arrows[arrow_index]; |
| 95 if (event.IsControlDown()) | 93 if (event.IsControlDown()) |
| 96 arrow = BubbleBorder::NONE; | 94 arrow = BubbleBorder::NONE; |
| 97 else if (event.IsAltDown()) | 95 else if (event.IsAltDown()) |
| 98 arrow = BubbleBorder::FLOAT; | 96 arrow = BubbleBorder::FLOAT; |
| 99 | 97 |
| 100 ExampleBubble* bubble = new ExampleBubble(sender, arrow); | 98 ExampleBubble* bubble = new ExampleBubble(sender, arrow); |
| 101 bubble->set_color(colors[(color_index++) % arraysize(colors)]); | 99 bubble->set_color(colors[(color_index++) % arraysize(colors)]); |
| 102 | 100 |
| 103 if (sender == shadow_) | 101 if (sender == no_shadow_) |
| 104 bubble->set_shadow(BubbleBorder::SHADOW); | |
| 105 else if (sender == no_shadow_) | |
| 106 bubble->set_shadow(BubbleBorder::NO_SHADOW); | 102 bubble->set_shadow(BubbleBorder::NO_SHADOW); |
| 107 else if (sender == big_shadow_) | 103 else if (sender == big_shadow_) |
| 108 bubble->set_shadow(BubbleBorder::BIG_SHADOW); | 104 bubble->set_shadow(BubbleBorder::BIG_SHADOW); |
| 109 else if (sender == small_shadow_) | 105 else if (sender == small_shadow_) |
| 110 bubble->set_shadow(BubbleBorder::SMALL_SHADOW); | 106 bubble->set_shadow(BubbleBorder::SMALL_SHADOW); |
| 111 | 107 |
| 112 if (sender == persistent_) { | 108 if (sender == persistent_) { |
| 113 bubble->set_close_on_deactivate(false); | 109 bubble->set_close_on_deactivate(false); |
| 114 bubble->set_move_with_anchor(true); | 110 bubble->set_move_with_anchor(true); |
| 115 } | 111 } |
| 116 | 112 |
| 117 BubbleDelegateView::CreateBubble(bubble); | 113 BubbleDelegateView::CreateBubble(bubble); |
| 118 if (sender == align_to_edge_) | 114 if (sender == align_to_edge_) |
| 119 bubble->SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 115 bubble->SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 120 | 116 |
| 121 if (sender == fade_in_) | 117 if (sender == fade_in_) |
| 122 bubble->StartFade(true); | 118 bubble->StartFade(true); |
| 123 else | 119 else |
| 124 bubble->GetWidget()->Show(); | 120 bubble->GetWidget()->Show(); |
| 125 } | 121 } |
| 126 | 122 |
| 127 } // namespace examples | 123 } // namespace examples |
| 128 } // namespace views | 124 } // namespace views |
| OLD | NEW |