Commit 43afa113 authored by estade@chromium.org's avatar estade@chromium.org

media galleries config dialog on views

BUG=134929

Review URL: https://chromiumcodereview.appspot.com/10828166

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151758 0039d316-1c4b-4281-b951-d872f2087c98
parent fc507794
......@@ -23,7 +23,7 @@
#include "base/sys_string_conversions.h"
#endif
#if defined(TOOLKIT_GTK)
#if !defined(OS_MACOSX)
#include "chrome/browser/media_gallery/media_galleries_dialog_controller.h"
#endif
......@@ -112,7 +112,7 @@ void MediaGalleriesGetMediaFileSystemsFunction::ShowDialog() {
return;
}
#if defined(TOOLKIT_GTK)
#if !defined(OS_MACOSX)
// Controller will delete itself.
new chrome::MediaGalleriesDialogController(
tab_contents, *GetExtension(),
......
......@@ -144,8 +144,6 @@ MediaGalleryPrefInfo::~MediaGalleryPrefInfo() {}
MediaGalleriesPreferences::MediaGalleriesPreferences(Profile* profile)
: profile_(profile) {
DCHECK(UserInteractionIsEnabled());
// Populate the default galleries if this is a fresh profile.
MediaGalleryPrefId current_id =
profile_->GetPrefs()->GetUint64(prefs::kMediaGalleriesUniqueId);
......@@ -399,9 +397,6 @@ string16 MediaGalleriesPreferences::ComputeDisplayName(const FilePath& path) {
// static
void MediaGalleriesPreferences::RegisterUserPrefs(PrefService* prefs) {
if (!UserInteractionIsEnabled())
return;
prefs->RegisterListPref(prefs::kMediaGalleriesRememberedGalleries,
PrefService::UNSYNCABLE_PREF);
prefs->RegisterUint64Pref(prefs::kMediaGalleriesUniqueId,
......
......@@ -17,7 +17,6 @@
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/media_gallery/media_file_system_registry.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/test/base/testing_profile.h"
......@@ -56,8 +55,6 @@ class MediaGalleriesPreferencesTest : public testing::Test {
}
virtual void SetUp() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableMediaGalleryUI);
extensions_dir_ = profile_->GetPath().AppendASCII("Extensions");
ASSERT_TRUE(file_util::CreateDirectory(extensions_dir_));
......@@ -67,7 +64,6 @@ class MediaGalleriesPreferencesTest : public testing::Test {
extension_service_ = extension_system->CreateExtensionService(
CommandLine::ForCurrentProcess(), extensions_dir_, false);
MediaGalleriesPreferences::RegisterUserPrefs(profile_->GetPrefs());
gallery_prefs_.reset(new MediaGalleriesPreferences(profile_.get()));
// Load the default galleries into the expectations.
......
......@@ -51,7 +51,8 @@ class NativeConstrainedWindow {
// ConstrainedWindowViews
//
// A ConstrainedWindow implementation that implements a Constrained Window as
// a child HWND with a custom window frame.
// a child HWND with a custom window frame. The ConstrainedWindowViews owns
// itself and will be deleted soon after being closed.
//
class ConstrainedWindowViews : public views::Widget,
public ConstrainedWindow,
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/extensions/media_galleries_dialog_views.h"
#include "chrome/browser/ui/views/constrained_window_views.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
#include "ui/views/view.h"
namespace chrome {
typedef MediaGalleriesDialogController::KnownGalleryPermissions
GalleryPermissions;
namespace {
// Heading font size correction.
#if defined(CROS_FONTS_USING_BCI)
const int kHeadingFontSizeDelta = 0;
#else
const int kHeadingFontSizeDelta = 1;
#endif
const int kContentWidth = 450;
} // namespace
MediaGalleriesDialogViews::MediaGalleriesDialogViews(
MediaGalleriesDialogController* controller)
: controller_(controller),
window_(NULL),
contents_(new views::View()),
checkbox_container_(NULL),
add_gallery_(NULL),
confirm_available_(false),
accepted_(false) {
InitChildViews();
// Ownership of |contents_| is handed off by this call. |window_| will take
// care of deleting itself after calling DeleteDelegate().
window_ = new ConstrainedWindowViews(controller->tab_contents(), this);
}
MediaGalleriesDialogViews::~MediaGalleriesDialogViews() {}
void MediaGalleriesDialogViews::InitChildViews() {
// Layout.
views::GridLayout* layout = new views::GridLayout(contents_);
layout->SetInsets(views::kPanelVertMargin, views::kPanelHorizMargin,
0, views::kPanelHorizMargin);
int column_set_id = 0;
views::ColumnSet* columns = layout->AddColumnSet(column_set_id);
columns->AddColumn(views::GridLayout::LEADING,
views::GridLayout::LEADING,
1,
views::GridLayout::FIXED,
kContentWidth,
0);
contents_->SetLayoutManager(layout);
// Header text.
views::Label* header = new views::Label(controller_->GetHeader());
header->SetFont(header->font().DeriveFont(kHeadingFontSizeDelta,
gfx::Font::BOLD));
header->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
layout->StartRow(0, column_set_id);
layout->AddView(header);
// Message text.
views::Label* subtext = new views::Label(controller_->GetSubtext());
subtext->SetMultiLine(true);
subtext->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
layout->StartRowWithPadding(0, column_set_id,
0, views::kRelatedControlVerticalSpacing);
layout->AddView(subtext);
// Checkboxes.
checkbox_container_ = new views::View();
checkbox_container_->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical,
views::kPanelHorizIndentation,
0,
views::kRelatedControlSmallVerticalSpacing));
layout->StartRowWithPadding(0, column_set_id,
0, views::kRelatedControlVerticalSpacing);
layout->AddView(checkbox_container_);
const GalleryPermissions& permissions = controller_->permissions();
for (GalleryPermissions::const_iterator iter = permissions.begin();
iter != permissions.end(); ++iter) {
AddOrUpdateGallery(&iter->second.pref_info, iter->second.allowed);
if (iter->second.allowed)
confirm_available_ = true;
}
// Add Gallery button.
add_gallery_ = new views::NativeTextButton(
this, l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY));
layout->StartRowWithPadding(0, column_set_id,
0, views::kRelatedControlVerticalSpacing);
layout->AddView(add_gallery_);
}
void MediaGalleriesDialogViews::UpdateGallery(
const MediaGalleryPrefInfo* gallery,
bool permitted) {
// After adding a new checkbox, we have to update the size of the dialog.
if (AddOrUpdateGallery(gallery, permitted))
GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
}
bool MediaGalleriesDialogViews::AddOrUpdateGallery(
const MediaGalleryPrefInfo* gallery,
bool permitted) {
CheckboxMap::iterator iter = checkbox_map_.find(gallery);
if (iter != checkbox_map_.end()) {
iter->second->SetChecked(permitted);
return false;
}
views::Checkbox* checkbox = new views::Checkbox(gallery->display_name);
checkbox->set_listener(this);
checkbox->SetTooltipText(gallery->path.LossyDisplayName());
checkbox_container_->AddChildView(checkbox);
checkbox->SetChecked(permitted);
checkbox_map_[gallery] = checkbox;
return true;
}
void MediaGalleriesDialogViews::DeleteDelegate() {
controller_->DialogFinished(accepted_);
}
views::Widget* MediaGalleriesDialogViews::GetWidget() {
return contents_->GetWidget();
}
const views::Widget* MediaGalleriesDialogViews::GetWidget() const {
return contents_->GetWidget();
}
views::View* MediaGalleriesDialogViews::GetContentsView() {
return contents_;
}
string16 MediaGalleriesDialogViews::GetDialogButtonLabel(
ui::DialogButton button) const {
return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ?
IDS_MEDIA_GALLERIES_DIALOG_CONFIRM :
IDS_MEDIA_GALLERIES_DIALOG_CANCEL);
}
bool MediaGalleriesDialogViews::IsDialogButtonEnabled(
ui::DialogButton button) const {
return button != ui::DIALOG_BUTTON_OK || confirm_available_;
}
bool MediaGalleriesDialogViews::Cancel() {
return true;
}
bool MediaGalleriesDialogViews::Accept() {
accepted_ = true;
return true;
}
void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender,
const ui::Event& event) {
confirm_available_ = true;
GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons();
if (sender == add_gallery_) {
controller_->OnAddFolderClicked();
return;
}
for (CheckboxMap::iterator iter = checkbox_map_.begin();
iter != checkbox_map_.end(); ++iter) {
if (sender == iter->second) {
controller_->GalleryToggled(
iter->first, static_cast<views::Checkbox*>(sender)->checked());
return;
}
}
NOTREACHED();
}
// MediaGalleriesDialogViewsController -----------------------------------------
// static
MediaGalleriesDialog* MediaGalleriesDialog::Create(
MediaGalleriesDialogController* controller) {
return new MediaGalleriesDialogViews(controller);
}
} // namespace chrome
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_
#include <map>
#include "base/compiler_specific.h"
#include "chrome/browser/media_gallery/media_galleries_dialog_controller.h"
#include "ui/views/window/dialog_delegate.h"
class ConstrainedWindowViews;
namespace views {
class Checkbox;
}
namespace chrome {
// The media galleries configuration view for Views. It will immediately show
// upon construction.
class MediaGalleriesDialogViews : public MediaGalleriesDialog,
public views::DialogDelegate,
public views::ButtonListener {
public:
explicit MediaGalleriesDialogViews(
MediaGalleriesDialogController* controller);
virtual ~MediaGalleriesDialogViews();
// MediaGalleriesDialog implementation:
virtual void UpdateGallery(const MediaGalleryPrefInfo* gallery,
bool permitted) OVERRIDE;
// views::DialogDelegate implementation:
virtual void DeleteDelegate() OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
virtual views::View* GetContentsView() OVERRIDE;
virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
virtual bool Cancel() OVERRIDE;
virtual bool Accept() OVERRIDE;
// views::ButtonListener implementation:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
private:
typedef std::map<const MediaGalleryPrefInfo*, views::Checkbox*> CheckboxMap;
void InitChildViews();
// Adds a checkbox or updates an existing checkbox. Returns true if a new one
// was added.
bool AddOrUpdateGallery(const MediaGalleryPrefInfo* gallery,
bool permitted);
MediaGalleriesDialogController* controller_;
// The constrained window (a weak pointer).
ConstrainedWindowViews* window_;
// The contents of the dialog. Owned by |window_|'s RootView.
views::View* contents_;
// A map from media gallery to views::Checkbox view.
CheckboxMap checkbox_map_;
views::View* checkbox_container_;
views::Button* add_gallery_;
// This tracks whether the confirm button can be clicked. It starts as false
// if no checkboxes are ticked. After there is any interaction, or some
// checkboxes start checked, this will be true.
bool confirm_available_;
// True if the user has pressed accept.
bool accepted_;
DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogViews);
};
} // namespace chrome
#endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_
......@@ -1445,6 +1445,7 @@
'browser/media_gallery/media_device_notifications_window_win.h',
'browser/media_gallery/media_file_system_registry.cc',
'browser/media_gallery/media_file_system_registry.h',
'browser/media_gallery/media_galleries_dialog_controller.cc',
'browser/media_gallery/media_galleries_dialog_controller.h',
'browser/media_gallery/media_galleries_preferences.cc',
'browser/media_gallery/media_galleries_preferences.h',
......@@ -3684,6 +3685,8 @@
'browser/ui/views/extensions/extension_uninstall_dialog_view.cc',
'browser/ui/views/extensions/extension_view.cc',
'browser/ui/views/extensions/extension_view.h',
'browser/ui/views/extensions/media_galleries_dialog_views.cc',
'browser/ui/views/extensions/media_galleries_dialog_views.h',
'browser/ui/views/extensions/shell_window_views.cc',
'browser/ui/views/extensions/shell_window_views.h',
'browser/ui/views/external_protocol_dialog.cc',
......@@ -4877,7 +4880,6 @@
'../third_party/undoview/undoview.gyp:undoview',
],
'sources': [
'browser/media_gallery/media_galleries_dialog_controller.cc',
'browser/ui/startup/obsolete_os_info_bar.cc',
'browser/ui/startup/obsolete_os_info_bar.h',
],
......@@ -5065,6 +5067,7 @@
'browser/importer/nss_decryptor_system_nss.h',
'browser/jankometer.cc',
'browser/lifetime/application_lifetime_stub.cc',
'browser/media_gallery/media_galleries_dialog_controller.cc',
'browser/password_manager/encryptor_posix.cc',
'browser/password_manager/login_database_posix.cc',
'browser/tab_contents/spellchecker_submenu_observer_hunspell.cc',
......
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