Commit 1b7a9a22 authored by ivankr@chromium.org's avatar ivankr@chromium.org

[cros] Change Picture prefs page: DOM initialization moved to separate handler from Initialize.

*) Also fixes image grid not loosing focus when closing Change Picture page with the close button.

BUG=chromium-os:23368
TEST=Manual: see bug description; both Backspace and Alt+Left should not trigger the bug.

Review URL: http://codereview.chromium.org/8879048

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114015 0039d316-1c4b-4281-b951-d872f2087c98
parent 19fbfc88
......@@ -67,6 +67,8 @@ cr.define('options', function() {
// Old user image data (if present).
this.oldImage_ = null;
chrome.send('onChangePicturePageInitialized');
},
/**
......@@ -74,15 +76,17 @@ cr.define('options', function() {
*/
didShowPage: function() {
$('images-grid').updateAndFocus();
chrome.send('onPageShown');
chrome.send('onChangePicturePageShown');
},
/**
* Called right before the page is hidden.
*/
willHidePage: function() {
var imageGrid = $('images-grid');
imageGrid.blur(); // Make sure the image grid is not active.
if (this.oldImage_) {
$('images-grid').removeItem(this.oldImage_);
imageGrid.removeItem(this.oldImage_);
this.oldImage_ = null;
}
},
......@@ -92,7 +96,6 @@ cr.define('options', function() {
* @private
*/
closePage_: function() {
$('images-grid').blur(); // Make sure the image grid is not active.
OptionsPage.navigateToPage('personal');
},
......@@ -230,11 +233,11 @@ cr.define('options', function() {
},
/**
* Appends received images to the image grid.
* @param {Array.<string>} images An array of URLs to user images.
* Appends default images to the image grid. Should only be called once.
* @param {Array.<string>} images An array of URLs to default images.
* @private
*/
setUserImages_: function(images) {
setDefaultImages_: function(images) {
var imageGrid = $('images-grid');
for (var i = 0, url; url = images[i]; i++) {
imageGrid.addItem(url);
......@@ -245,10 +248,10 @@ cr.define('options', function() {
// Forward public APIs to private implementations.
[
'setCameraPresent',
'setDefaultImages',
'setOldImage',
'setProfileImage',
'setSelectedImage',
'setUserImages',
].forEach(function(name) {
ChangePictureOptions[name] = function(value1, value2) {
ChangePictureOptions.getInstance()[name + '_'](value1, value2);
......
......@@ -73,21 +73,6 @@ ChangePictureOptionsHandler::~ChangePictureOptionsHandler() {
select_file_dialog_->ListenerDestroyed();
}
void ChangePictureOptionsHandler::Initialize() {
// If no camera presence check has been performed in this session,
// start one now.
if (CameraDetector::camera_presence() ==
CameraDetector::kCameraPresenceUnknown)
CheckCameraPresence();
// While the check is in progress, use previous camera presence state and
// presume it is present if no check has been performed yet.
SetCameraPresent(CameraDetector::camera_presence() !=
CameraDetector::kCameraAbsent);
SendAvailableImages();
}
void ChangePictureOptionsHandler::GetLocalizedValues(
DictionaryValue* localized_strings) {
DCHECK(localized_strings);
......@@ -114,20 +99,23 @@ void ChangePictureOptionsHandler::RegisterMessages() {
web_ui_->RegisterMessageCallback("takePhoto",
base::Bind(&ChangePictureOptionsHandler::HandleTakePhoto,
base::Unretained(this)));
web_ui_->RegisterMessageCallback("onPageShown",
base::Bind(&ChangePictureOptionsHandler::HandleOnPageShown,
web_ui_->RegisterMessageCallback("onChangePicturePageShown",
base::Bind(&ChangePictureOptionsHandler::HandlePageShown,
base::Unretained(this)));
web_ui_->RegisterMessageCallback("onChangePicturePageInitialized",
base::Bind(&ChangePictureOptionsHandler::HandlePageInitialized,
base::Unretained(this)));
web_ui_->RegisterMessageCallback("selectImage",
base::Bind(&ChangePictureOptionsHandler::HandleSelectImage,
base::Unretained(this)));
}
void ChangePictureOptionsHandler::SendAvailableImages() {
void ChangePictureOptionsHandler::SendDefaultImages() {
ListValue image_urls;
for (int i = 0; i < kDefaultImagesCount; ++i) {
image_urls.Append(new StringValue(GetDefaultImageUrl(i)));
}
web_ui_->CallJavascriptFunction("ChangePictureOptions.setUserImages",
web_ui_->CallJavascriptFunction("ChangePictureOptions.setDefaultImages",
image_urls);
}
......@@ -168,9 +156,29 @@ void ChangePictureOptionsHandler::HandleTakePhoto(const ListValue* args) {
window->Show();
}
void ChangePictureOptionsHandler::HandleOnPageShown(
void ChangePictureOptionsHandler::HandlePageInitialized(
const base::ListValue* args) {
DCHECK(args && args->empty());
// If no camera presence check has been performed in this session,
// start one now.
if (CameraDetector::camera_presence() ==
CameraDetector::kCameraPresenceUnknown) {
CheckCameraPresence();
}
// While the check is in progress, use previous camera presence state and
// presume it is present if no check has been performed yet.
SetCameraPresent(CameraDetector::camera_presence() !=
CameraDetector::kCameraAbsent);
SendDefaultImages();
}
void ChangePictureOptionsHandler::HandlePageShown(const base::ListValue* args) {
DCHECK(args && args->empty());
// TODO(ivankr): If user opens settings and goes to Change Picture page right
// after the check started |HandlePageInitialized| has been completed,
// |CheckCameraPresence| will be called twice, should be throttled.
CheckCameraPresence();
SendSelectedImage();
UpdateProfileImage();
......
......@@ -28,7 +28,6 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler,
virtual ~ChangePictureOptionsHandler();
// OptionsPageUIHandler implementation.
virtual void Initialize() OVERRIDE;
virtual void GetLocalizedValues(
base::DictionaryValue* localized_strings) OVERRIDE;
......@@ -37,7 +36,7 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler,
private:
// Sends list of available default images to the page.
void SendAvailableImages();
void SendDefaultImages();
// Sends current selection to the page.
void SendSelectedImage();
......@@ -65,8 +64,11 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler,
// Gets the list of available user images and sends it to the page.
void HandleGetAvailableImages(const base::ListValue* args);
// Handles page initialized event.
void HandlePageInitialized(const base::ListValue* args);
// Handles page shown event.
void HandleOnPageShown(const base::ListValue* args);
void HandlePageShown(const base::ListValue* args);
// Selects one of the available images as user's.
void HandleSelectImage(const base::ListValue* args);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment