| 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/button_example.h" | 5 #include "ui/views/examples/button_example.h" | 
| 6 | 6 | 
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" | 
| 8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" | 
| 9 #include "ui/gfx/image/image.h" | 9 #include "ui/gfx/image/image.h" | 
| 10 #include "ui/resources/grit/ui_resources.h" | 10 #include "ui/resources/grit/ui_resources.h" | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 81   image_button_->SetFocusable(true); | 81   image_button_->SetFocusable(true); | 
| 82   image_button_->SetImage(ImageButton::STATE_NORMAL, | 82   image_button_->SetImage(ImageButton::STATE_NORMAL, | 
| 83                           rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); | 83                           rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); | 
| 84   image_button_->SetImage(ImageButton::STATE_HOVERED, | 84   image_button_->SetImage(ImageButton::STATE_HOVERED, | 
| 85                           rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); | 85                           rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); | 
| 86   image_button_->SetImage(ImageButton::STATE_PRESSED, | 86   image_button_->SetImage(ImageButton::STATE_PRESSED, | 
| 87                           rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); | 87                           rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); | 
| 88   container->AddChildView(image_button_); | 88   container->AddChildView(image_button_); | 
| 89 } | 89 } | 
| 90 | 90 | 
| 91 void ButtonExample::LabelButtonPressed(const ui::Event& event) { | 91 void ButtonExample::LabelButtonPressed(LabelButton* label_button, | 
|  | 92                                        const ui::Event& event) { | 
| 92   PrintStatus("Label Button Pressed! count: %d", ++count_); | 93   PrintStatus("Label Button Pressed! count: %d", ++count_); | 
| 93   if (event.IsControlDown()) { | 94   if (event.IsControlDown()) { | 
| 94     if (event.IsShiftDown()) { | 95     if (event.IsShiftDown()) { | 
| 95       label_button_->SetText(ASCIIToUTF16( | 96       label_button->SetText(ASCIIToUTF16( | 
| 96           label_button_->GetText().empty() | 97           label_button->GetText().empty() | 
| 97               ? kLongText | 98               ? kLongText | 
| 98               : label_button_->GetText().length() > 50 ? kLabelButton : "")); | 99               : label_button->GetText().length() > 50 ? kLabelButton : "")); | 
| 99     } else if (event.IsAltDown()) { | 100     } else if (event.IsAltDown()) { | 
| 100       label_button_->SetImage(Button::STATE_NORMAL, | 101       label_button->SetImage( | 
| 101           label_button_->GetImage(Button::STATE_NORMAL).isNull() ? | 102           Button::STATE_NORMAL, | 
| 102           *icon_ : gfx::ImageSkia()); | 103           label_button->GetImage(Button::STATE_NORMAL).isNull() | 
|  | 104               ? *icon_ | 
|  | 105               : gfx::ImageSkia()); | 
| 103     } else { | 106     } else { | 
| 104       static int alignment = 0; | 107       static int alignment = 0; | 
| 105       label_button_->SetHorizontalAlignment( | 108       label_button->SetHorizontalAlignment( | 
| 106           static_cast<gfx::HorizontalAlignment>(++alignment % 3)); | 109           static_cast<gfx::HorizontalAlignment>(++alignment % 3)); | 
| 107     } | 110     } | 
| 108   } else if (event.IsShiftDown()) { | 111   } else if (event.IsShiftDown()) { | 
| 109     if (event.IsAltDown()) { | 112     if (event.IsAltDown()) { | 
| 110       label_button_->SetFocusable(!label_button_->IsFocusable()); | 113       label_button->SetFocusable(!label_button->IsFocusable()); | 
| 111     } else { | 114     } else { | 
| 112       label_button_->SetStyle(static_cast<Button::ButtonStyle>( | 115       label_button->SetStyle(static_cast<Button::ButtonStyle>( | 
| 113           (label_button_->style() + 1) % Button::STYLE_COUNT)); | 116           (label_button->style() + 1) % Button::STYLE_COUNT)); | 
| 114     } | 117     } | 
| 115   } else if (event.IsAltDown()) { | 118   } else if (event.IsAltDown()) { | 
| 116     label_button_->SetIsDefault(!label_button_->is_default()); | 119     label_button->SetIsDefault(!label_button->is_default()); | 
| 117   } else { | 120   } else { | 
| 118     label_button_->SetMinSize(gfx::Size()); | 121     label_button->SetMinSize(gfx::Size()); | 
| 119   } | 122   } | 
| 120   example_view()->GetLayoutManager()->Layout(example_view()); | 123   example_view()->GetLayoutManager()->Layout(example_view()); | 
| 121 } | 124 } | 
| 122 | 125 | 
| 123 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { | 126 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { | 
| 124   if (sender == label_button_) | 127   LabelButton* label_button = CustomButton::AsLabelButton(sender); | 
| 125     LabelButtonPressed(event); | 128   if (label_button) | 
|  | 129     LabelButtonPressed(label_button, event); | 
| 126   else | 130   else | 
| 127     PrintStatus("Image Button Pressed! count: %d", ++count_); | 131     PrintStatus("Image Button Pressed! count: %d", ++count_); | 
| 128 } | 132 } | 
| 129 | 133 | 
| 130 }  // namespace examples | 134 }  // namespace examples | 
| 131 }  // namespace views | 135 }  // namespace views | 
| OLD | NEW | 
|---|