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/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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 InitLayout(); | 101 InitLayout(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 int DefaultImagesView::GetDefaultImageIndex() const { | 104 int DefaultImagesView::GetDefaultImageIndex() const { |
| 105 if (selected_image_index_ == -1) | 105 if (selected_image_index_ == -1) |
| 106 return -1; | 106 return -1; |
| 107 else | 107 else |
| 108 return selected_image_index_ - 1; | 108 return selected_image_index_ - 1; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void DefaultImagesView::SetDefaultImageIndex(int image_index) { | |
| 112 selected_image_index_ = image_index + 1; | |
|
Nikita (slow)
2011/05/16 16:45:16
nit: Please comment that we're skipping camera ima
whywhat
2011/05/17 12:25:43
Done.
I introduced a named constant and put a comm
| |
| 113 if (delegate_) | |
| 114 delegate_->OnImageSelected(image_index % kDefaultImagesCount); | |
| 115 } | |
| 116 | |
| 111 void DefaultImagesView::ClearSelection() { | 117 void DefaultImagesView::ClearSelection() { |
| 112 selected_image_index_ = -1; | 118 selected_image_index_ = -1; |
| 113 } | 119 } |
| 114 | 120 |
| 115 gfx::Size DefaultImagesView::GetPreferredSize() { | 121 gfx::Size DefaultImagesView::GetPreferredSize() { |
| 116 int image_size_with_margin = (kDefaultImageSize + 2 * kImageBorderSize); | 122 int image_size_with_margin = (kDefaultImageSize + 2 * kImageBorderSize); |
| 117 int width = kColumnsCount * image_size_with_margin + | 123 int width = kColumnsCount * image_size_with_margin + |
| 118 (kColumnsCount - 1) * kHorizontalPadding; | 124 (kColumnsCount - 1) * kHorizontalPadding; |
| 119 size_t image_count = default_images_.size(); | 125 size_t image_count = default_images_.size(); |
| 120 int rows_count = (image_count + kColumnsCount - 1) / kColumnsCount; | 126 int rows_count = (image_count + kColumnsCount - 1) / kColumnsCount; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 134 if (sender->GetID() == kCaptureButtonId) { | 140 if (sender->GetID() == kCaptureButtonId) { |
| 135 if (delegate_) | 141 if (delegate_) |
| 136 delegate_->OnCaptureButtonClicked(); | 142 delegate_->OnCaptureButtonClicked(); |
| 137 } else { | 143 } else { |
| 138 int image_index = sender->GetID() - kImageStartId; | 144 int image_index = sender->GetID() - kImageStartId; |
| 139 int images_count = static_cast<int>(default_images_.size()); | 145 int images_count = static_cast<int>(default_images_.size()); |
| 140 if (image_index < 0 || image_index >= images_count) { | 146 if (image_index < 0 || image_index >= images_count) { |
| 141 NOTREACHED() << "Got ButtonPressed event from a view with wrong id."; | 147 NOTREACHED() << "Got ButtonPressed event from a view with wrong id."; |
| 142 return; | 148 return; |
| 143 } | 149 } |
| 144 selected_image_index_ = image_index + 1; | 150 SetDefaultImageIndex(image_index); |
| 145 if (delegate_) | |
| 146 delegate_->OnImageSelected(image_index % kDefaultImagesCount); | |
| 147 } | 151 } |
| 148 } | 152 } |
| 149 | 153 |
| 150 void DefaultImagesView::InitButton(int resource_id, | 154 void DefaultImagesView::InitButton(int resource_id, |
| 151 UserImageButton* button) const { | 155 UserImageButton* button) const { |
| 152 const SkBitmap* original_image = | 156 const SkBitmap* original_image = |
| 153 ResourceBundle::GetSharedInstance().GetBitmapNamed(resource_id); | 157 ResourceBundle::GetSharedInstance().GetBitmapNamed(resource_id); |
| 154 SkBitmap resized_image = skia::ImageOperations::Resize( | 158 SkBitmap resized_image = skia::ImageOperations::Resize( |
| 155 *original_image, | 159 *original_image, |
| 156 skia::ImageOperations::RESIZE_BEST, | 160 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) { | 207 for (int column = 0; column < kColumnsCount; ++column) { |
| 204 if (current_image >= image_count) | 208 if (current_image >= image_count) |
| 205 break; | 209 break; |
| 206 layout->AddView(default_images_[current_image]); | 210 layout->AddView(default_images_[current_image]); |
| 207 ++current_image; | 211 ++current_image; |
| 208 } | 212 } |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 | 215 |
| 212 } // namespace chromeos | 216 } // namespace chromeos |
| OLD | NEW |