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() { ...@@ -67,6 +67,8 @@ cr.define('options', function() {
// Old user image data (if present). // Old user image data (if present).
this.oldImage_ = null; this.oldImage_ = null;
chrome.send('onChangePicturePageInitialized');
}, },
/** /**
...@@ -74,15 +76,17 @@ cr.define('options', function() { ...@@ -74,15 +76,17 @@ cr.define('options', function() {
*/ */
didShowPage: function() { didShowPage: function() {
$('images-grid').updateAndFocus(); $('images-grid').updateAndFocus();
chrome.send('onPageShown'); chrome.send('onChangePicturePageShown');
}, },
/** /**
* Called right before the page is hidden. * Called right before the page is hidden.
*/ */
willHidePage: function() { willHidePage: function() {
var imageGrid = $('images-grid');
imageGrid.blur(); // Make sure the image grid is not active.
if (this.oldImage_) { if (this.oldImage_) {
$('images-grid').removeItem(this.oldImage_); imageGrid.removeItem(this.oldImage_);
this.oldImage_ = null; this.oldImage_ = null;
} }
}, },
...@@ -92,7 +96,6 @@ cr.define('options', function() { ...@@ -92,7 +96,6 @@ cr.define('options', function() {
* @private * @private
*/ */
closePage_: function() { closePage_: function() {
$('images-grid').blur(); // Make sure the image grid is not active.
OptionsPage.navigateToPage('personal'); OptionsPage.navigateToPage('personal');
}, },
...@@ -230,11 +233,11 @@ cr.define('options', function() { ...@@ -230,11 +233,11 @@ cr.define('options', function() {
}, },
/** /**
* Appends received images to the image grid. * Appends default images to the image grid. Should only be called once.
* @param {Array.<string>} images An array of URLs to user images. * @param {Array.<string>} images An array of URLs to default images.
* @private * @private
*/ */
setUserImages_: function(images) { setDefaultImages_: function(images) {
var imageGrid = $('images-grid'); var imageGrid = $('images-grid');
for (var i = 0, url; url = images[i]; i++) { for (var i = 0, url; url = images[i]; i++) {
imageGrid.addItem(url); imageGrid.addItem(url);
...@@ -245,10 +248,10 @@ cr.define('options', function() { ...@@ -245,10 +248,10 @@ cr.define('options', function() {
// Forward public APIs to private implementations. // Forward public APIs to private implementations.
[ [
'setCameraPresent', 'setCameraPresent',
'setDefaultImages',
'setOldImage', 'setOldImage',
'setProfileImage', 'setProfileImage',
'setSelectedImage', 'setSelectedImage',
'setUserImages',
].forEach(function(name) { ].forEach(function(name) {
ChangePictureOptions[name] = function(value1, value2) { ChangePictureOptions[name] = function(value1, value2) {
ChangePictureOptions.getInstance()[name + '_'](value1, value2); ChangePictureOptions.getInstance()[name + '_'](value1, value2);
......
...@@ -73,21 +73,6 @@ ChangePictureOptionsHandler::~ChangePictureOptionsHandler() { ...@@ -73,21 +73,6 @@ ChangePictureOptionsHandler::~ChangePictureOptionsHandler() {
select_file_dialog_->ListenerDestroyed(); 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( void ChangePictureOptionsHandler::GetLocalizedValues(
DictionaryValue* localized_strings) { DictionaryValue* localized_strings) {
DCHECK(localized_strings); DCHECK(localized_strings);
...@@ -114,20 +99,23 @@ void ChangePictureOptionsHandler::RegisterMessages() { ...@@ -114,20 +99,23 @@ void ChangePictureOptionsHandler::RegisterMessages() {
web_ui_->RegisterMessageCallback("takePhoto", web_ui_->RegisterMessageCallback("takePhoto",
base::Bind(&ChangePictureOptionsHandler::HandleTakePhoto, base::Bind(&ChangePictureOptionsHandler::HandleTakePhoto,
base::Unretained(this))); base::Unretained(this)));
web_ui_->RegisterMessageCallback("onPageShown", web_ui_->RegisterMessageCallback("onChangePicturePageShown",
base::Bind(&ChangePictureOptionsHandler::HandleOnPageShown, base::Bind(&ChangePictureOptionsHandler::HandlePageShown,
base::Unretained(this)));
web_ui_->RegisterMessageCallback("onChangePicturePageInitialized",
base::Bind(&ChangePictureOptionsHandler::HandlePageInitialized,
base::Unretained(this))); base::Unretained(this)));
web_ui_->RegisterMessageCallback("selectImage", web_ui_->RegisterMessageCallback("selectImage",
base::Bind(&ChangePictureOptionsHandler::HandleSelectImage, base::Bind(&ChangePictureOptionsHandler::HandleSelectImage,
base::Unretained(this))); base::Unretained(this)));
} }
void ChangePictureOptionsHandler::SendAvailableImages() { void ChangePictureOptionsHandler::SendDefaultImages() {
ListValue image_urls; ListValue image_urls;
for (int i = 0; i < kDefaultImagesCount; ++i) { for (int i = 0; i < kDefaultImagesCount; ++i) {
image_urls.Append(new StringValue(GetDefaultImageUrl(i))); image_urls.Append(new StringValue(GetDefaultImageUrl(i)));
} }
web_ui_->CallJavascriptFunction("ChangePictureOptions.setUserImages", web_ui_->CallJavascriptFunction("ChangePictureOptions.setDefaultImages",
image_urls); image_urls);
} }
...@@ -168,9 +156,29 @@ void ChangePictureOptionsHandler::HandleTakePhoto(const ListValue* args) { ...@@ -168,9 +156,29 @@ void ChangePictureOptionsHandler::HandleTakePhoto(const ListValue* args) {
window->Show(); window->Show();
} }
void ChangePictureOptionsHandler::HandleOnPageShown( void ChangePictureOptionsHandler::HandlePageInitialized(
const base::ListValue* args) { const base::ListValue* args) {
DCHECK(args && args->empty()); 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(); CheckCameraPresence();
SendSelectedImage(); SendSelectedImage();
UpdateProfileImage(); UpdateProfileImage();
......
...@@ -28,7 +28,6 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler, ...@@ -28,7 +28,6 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler,
virtual ~ChangePictureOptionsHandler(); virtual ~ChangePictureOptionsHandler();
// OptionsPageUIHandler implementation. // OptionsPageUIHandler implementation.
virtual void Initialize() OVERRIDE;
virtual void GetLocalizedValues( virtual void GetLocalizedValues(
base::DictionaryValue* localized_strings) OVERRIDE; base::DictionaryValue* localized_strings) OVERRIDE;
...@@ -37,7 +36,7 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler, ...@@ -37,7 +36,7 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler,
private: private:
// Sends list of available default images to the page. // Sends list of available default images to the page.
void SendAvailableImages(); void SendDefaultImages();
// Sends current selection to the page. // Sends current selection to the page.
void SendSelectedImage(); void SendSelectedImage();
...@@ -65,8 +64,11 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler, ...@@ -65,8 +64,11 @@ class ChangePictureOptionsHandler : public OptionsPageUIHandler,
// Gets the list of available user images and sends it to the page. // Gets the list of available user images and sends it to the page.
void HandleGetAvailableImages(const base::ListValue* args); void HandleGetAvailableImages(const base::ListValue* args);
// Handles page initialized event.
void HandlePageInitialized(const base::ListValue* args);
// Handles page shown event. // 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. // Selects one of the available images as user's.
void HandleSelectImage(const base::ListValue* args); 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