| 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/chromeos/login/default_images_view.h" | 5 #include "chrome/browser/chromeos/login/default_images_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/chromeos/login/default_user_images.h" | 9 #include "chrome/browser/chromeos/login/default_user_images.h" |
| 10 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" | 10 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const int kImageBorderSize = 1; | 39 const int kImageBorderSize = 1; |
| 40 // Color of default image border. | 40 // Color of default image border. |
| 41 const SkColor kImageBorderColor = SkColorSetARGB(38, 0, 0, 0); | 41 const SkColor kImageBorderColor = SkColorSetARGB(38, 0, 0, 0); |
| 42 // Color of default image background. | 42 // Color of default image background. |
| 43 const SkColor kImageBackgroundColor = SK_ColorWHITE; | 43 const SkColor kImageBackgroundColor = SK_ColorWHITE; |
| 44 // We give each image control an ID so we could distinguish them. Since 0 is | 44 // We give each image control an ID so we could distinguish them. Since 0 is |
| 45 // the default ID we want an offset for IDs we set. | 45 // the default ID we want an offset for IDs we set. |
| 46 const int kImageStartId = 100; | 46 const int kImageStartId = 100; |
| 47 // ID for image control for video capture. | 47 // ID for image control for video capture. |
| 48 const int kCaptureButtonId = 1000; | 48 const int kCaptureButtonId = 1000; |
| 49 // A number of the first buttons that don't correspond to any default image |
| 50 // (i.e. button to take a photo). |
| 51 const int kNonDefaultImageButtonsCount = 1; |
| 49 | 52 |
| 50 } // namespace | 53 } // namespace |
| 51 | 54 |
| 52 // Image button with border and background. Corrects view size by border | 55 // Image button with border and background. Corrects view size by border |
| 53 // insets as ImageButton ignores it. | 56 // insets as ImageButton ignores it. |
| 54 class UserImageButton : public views::ImageButton { | 57 class UserImageButton : public views::ImageButton { |
| 55 public: | 58 public: |
| 56 explicit UserImageButton(views::ButtonListener* listener); | 59 explicit UserImageButton(views::ButtonListener* listener); |
| 57 | 60 |
| 58 // Overridden from views::View: | 61 // Overridden from views::View: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 InitButton(kDefaultImageResources[i], image_button); | 101 InitButton(kDefaultImageResources[i], image_button); |
| 99 default_images_.push_back(image_button); | 102 default_images_.push_back(image_button); |
| 100 } | 103 } |
| 101 InitLayout(); | 104 InitLayout(); |
| 102 } | 105 } |
| 103 | 106 |
| 104 int DefaultImagesView::GetDefaultImageIndex() const { | 107 int DefaultImagesView::GetDefaultImageIndex() const { |
| 105 if (selected_image_index_ == -1) | 108 if (selected_image_index_ == -1) |
| 106 return -1; | 109 return -1; |
| 107 else | 110 else |
| 108 return selected_image_index_ - 1; | 111 return selected_image_index_ - kNonDefaultImageButtonsCount; |
| 112 } |
| 113 |
| 114 void DefaultImagesView::SetDefaultImageIndex(int image_index) { |
| 115 selected_image_index_ = image_index + kNonDefaultImageButtonsCount; |
| 116 if (delegate_) |
| 117 delegate_->OnImageSelected(image_index % kDefaultImagesCount); |
| 109 } | 118 } |
| 110 | 119 |
| 111 void DefaultImagesView::ClearSelection() { | 120 void DefaultImagesView::ClearSelection() { |
| 112 selected_image_index_ = -1; | 121 selected_image_index_ = -1; |
| 113 } | 122 } |
| 114 | 123 |
| 115 gfx::Size DefaultImagesView::GetPreferredSize() { | 124 gfx::Size DefaultImagesView::GetPreferredSize() { |
| 116 int image_size_with_margin = (kDefaultImageSize + 2 * kImageBorderSize); | 125 int image_size_with_margin = (kDefaultImageSize + 2 * kImageBorderSize); |
| 117 int width = kColumnsCount * image_size_with_margin + | 126 int width = kColumnsCount * image_size_with_margin + |
| 118 (kColumnsCount - 1) * kHorizontalPadding; | 127 (kColumnsCount - 1) * kHorizontalPadding; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 134 if (sender->GetID() == kCaptureButtonId) { | 143 if (sender->GetID() == kCaptureButtonId) { |
| 135 if (delegate_) | 144 if (delegate_) |
| 136 delegate_->OnCaptureButtonClicked(); | 145 delegate_->OnCaptureButtonClicked(); |
| 137 } else { | 146 } else { |
| 138 int image_index = sender->GetID() - kImageStartId; | 147 int image_index = sender->GetID() - kImageStartId; |
| 139 int images_count = static_cast<int>(default_images_.size()); | 148 int images_count = static_cast<int>(default_images_.size()); |
| 140 if (image_index < 0 || image_index >= images_count) { | 149 if (image_index < 0 || image_index >= images_count) { |
| 141 NOTREACHED() << "Got ButtonPressed event from a view with wrong id."; | 150 NOTREACHED() << "Got ButtonPressed event from a view with wrong id."; |
| 142 return; | 151 return; |
| 143 } | 152 } |
| 144 selected_image_index_ = image_index + 1; | 153 SetDefaultImageIndex(image_index); |
| 145 if (delegate_) | |
| 146 delegate_->OnImageSelected(image_index % kDefaultImagesCount); | |
| 147 } | 154 } |
| 148 } | 155 } |
| 149 | 156 |
| 150 void DefaultImagesView::InitButton(int resource_id, | 157 void DefaultImagesView::InitButton(int resource_id, |
| 151 UserImageButton* button) const { | 158 UserImageButton* button) const { |
| 152 const SkBitmap* original_image = | 159 const SkBitmap* original_image = |
| 153 ResourceBundle::GetSharedInstance().GetBitmapNamed(resource_id); | 160 ResourceBundle::GetSharedInstance().GetBitmapNamed(resource_id); |
| 154 SkBitmap resized_image = skia::ImageOperations::Resize( | 161 SkBitmap resized_image = skia::ImageOperations::Resize( |
| 155 *original_image, | 162 *original_image, |
| 156 skia::ImageOperations::RESIZE_BEST, | 163 skia::ImageOperations::RESIZE_BEST, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 for (int column = 0; column < kColumnsCount; ++column) { | 210 for (int column = 0; column < kColumnsCount; ++column) { |
| 204 if (current_image >= image_count) | 211 if (current_image >= image_count) |
| 205 break; | 212 break; |
| 206 layout->AddView(default_images_[current_image]); | 213 layout->AddView(default_images_[current_image]); |
| 207 ++current_image; | 214 ++current_image; |
| 208 } | 215 } |
| 209 } | 216 } |
| 210 } | 217 } |
| 211 | 218 |
| 212 } // namespace chromeos | 219 } // namespace chromeos |
| OLD | NEW |