| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/bookmarks/bookmark_editor_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/prefs/public/pref_service_base.h" | 11 #include "base/prefs/public/pref_service_base.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_utils.h" | 16 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 17 #include "chrome/browser/history/history.h" | 17 #include "chrome/browser/history/history.h" |
| 18 #include "chrome/browser/net/url_fixer_upper.h" | 18 #include "chrome/browser/net/url_fixer_upper.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 20 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
| 25 #include "ui/base/events/event.h" | 25 #include "ui/base/events/event.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/views/background.h" | 27 #include "ui/views/background.h" |
| 28 #include "ui/views/controls/button/chrome_style.h" |
| 28 #include "ui/views/controls/button/text_button.h" | 29 #include "ui/views/controls/button/text_button.h" |
| 29 #include "ui/views/controls/label.h" | 30 #include "ui/views/controls/label.h" |
| 30 #include "ui/views/controls/menu/menu_model_adapter.h" | 31 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 31 #include "ui/views/controls/menu/menu_runner.h" | 32 #include "ui/views/controls/menu/menu_runner.h" |
| 32 #include "ui/views/controls/textfield/textfield.h" | 33 #include "ui/views/controls/textfield/textfield.h" |
| 33 #include "ui/views/controls/tree/tree_view.h" | 34 #include "ui/views/controls/tree/tree_view.h" |
| 34 #include "ui/views/focus/focus_manager.h" | 35 #include "ui/views/focus/focus_manager.h" |
| 35 #include "ui/views/layout/grid_layout.h" | 36 #include "ui/views/layout/grid_layout.h" |
| 36 #include "ui/views/layout/layout_constants.h" | 37 #include "ui/views/layout/layout_constants.h" |
| 37 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
| 38 #include "ui/views/window/dialog_client_view.h" | 39 #include "ui/views/window/dialog_client_view.h" |
| 39 | 40 |
| 40 using views::GridLayout; | 41 using views::GridLayout; |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 // Background color of text field when URL is invalid. | 45 // Background color of text field when URL is invalid. |
| 45 const SkColor kErrorColor = SkColorSetRGB(0xFF, 0xBC, 0xBC); | 46 const SkColor kErrorColor = SkColorSetRGB(0xFF, 0xBC, 0xBC); |
| 46 | 47 |
| 47 // Preferred width of the tree. | |
| 48 const int kTreeWidth = 300; | |
| 49 | |
| 50 } // namespace | 48 } // namespace |
| 51 | 49 |
| 52 // static | 50 // static |
| 53 void BookmarkEditor::Show(gfx::NativeWindow parent_window, | 51 void BookmarkEditor::Show(gfx::NativeWindow parent_window, |
| 54 Profile* profile, | 52 Profile* profile, |
| 55 const EditDetails& details, | 53 const EditDetails& details, |
| 56 Configuration configuration) { | 54 Configuration configuration) { |
| 57 DCHECK(profile); | 55 DCHECK(profile); |
| 58 BookmarkEditorView* editor = new BookmarkEditorView(profile, | 56 BookmarkEditorView* editor = new BookmarkEditorView(profile, |
| 59 details.parent_node, details, configuration); | 57 details.parent_node, details, configuration); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // Otherwise save changes and close the dialog box. | 128 // Otherwise save changes and close the dialog box. |
| 131 ApplyEdits(); | 129 ApplyEdits(); |
| 132 return true; | 130 return true; |
| 133 } | 131 } |
| 134 | 132 |
| 135 bool BookmarkEditorView::AreAcceleratorsEnabled(ui::DialogButton button) { | 133 bool BookmarkEditorView::AreAcceleratorsEnabled(ui::DialogButton button) { |
| 136 return !show_tree_ || !tree_view_->GetEditingNode(); | 134 return !show_tree_ || !tree_view_->GetEditingNode(); |
| 137 } | 135 } |
| 138 | 136 |
| 139 void BookmarkEditorView::Layout() { | 137 void BookmarkEditorView::Layout() { |
| 140 // Let the grid layout manager lay out most of the dialog... | |
| 141 GetLayoutManager()->Layout(this); | 138 GetLayoutManager()->Layout(this); |
| 142 | 139 |
| 143 if (!show_tree_) | 140 if (!show_tree_) |
| 144 return; | 141 return; |
| 145 | 142 |
| 146 // Manually lay out the New Folder button in the same row as the OK/Cancel | 143 // Manually align the New Folder button with the Save and Cancel buttons. |
| 147 // buttons... | 144 gfx::Size size = new_folder_button_->GetPreferredSize(); |
| 148 gfx::Rect parent_bounds = parent()->GetContentsBounds(); | 145 gfx::Rect parent_bounds = parent()->GetContentsBounds(); |
| 149 gfx::Size prefsize = new_folder_button_->GetPreferredSize(); | 146 int x = views::DialogDelegate::UseNewStyle() ? 0 : views::kPanelHorizMargin; |
| 150 int button_y = | 147 int y = views::DialogDelegate::UseNewStyle() ? GetLocalBounds().bottom() : |
| 151 parent_bounds.bottom() - prefsize.height() - views::kButtonVEdgeMargin; | 148 parent_bounds.bottom() - size.height() - views::kButtonVEdgeMargin; |
| 152 new_folder_button_->SetBounds( | 149 new_folder_button_->SetBounds(x, y, size.width(), size.height()); |
| 153 views::kPanelHorizMargin, button_y, prefsize.width(), prefsize.height()); | |
| 154 } | 150 } |
| 155 | 151 |
| 156 gfx::Size BookmarkEditorView::GetPreferredSize() { | 152 gfx::Size BookmarkEditorView::GetPreferredSize() { |
| 157 if (!show_tree_) | 153 if (!show_tree_) |
| 158 return views::View::GetPreferredSize(); | 154 return views::View::GetPreferredSize(); |
| 159 | 155 |
| 160 return gfx::Size(views::Widget::GetLocalizedContentsSize( | 156 return gfx::Size(views::Widget::GetLocalizedContentsSize( |
| 161 IDS_EDITBOOKMARK_DIALOG_WIDTH_CHARS, | 157 IDS_EDITBOOKMARK_DIALOG_WIDTH_CHARS, |
| 162 IDS_EDITBOOKMARK_DIALOG_HEIGHT_LINES)); | 158 IDS_EDITBOOKMARK_DIALOG_HEIGHT_LINES)); |
| 163 } | 159 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 239 } |
| 244 deletes_.push_back(node->value); | 240 deletes_.push_back(node->value); |
| 245 } | 241 } |
| 246 tree_model_->Remove(node->parent(), node); | 242 tree_model_->Remove(node->parent(), node); |
| 247 } else { | 243 } else { |
| 248 DCHECK_EQ(IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM, command_id); | 244 DCHECK_EQ(IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM, command_id); |
| 249 NewFolder(); | 245 NewFolder(); |
| 250 } | 246 } |
| 251 } | 247 } |
| 252 | 248 |
| 253 void BookmarkEditorView::Show(gfx::NativeWindow parent_window) { | 249 void BookmarkEditorView::Show(gfx::NativeWindow parent) { |
| 254 views::Widget::CreateWindowWithParent(this, parent_window); | 250 views::DialogDelegateView::CreateDialogWidget(this, NULL, parent); |
| 255 UserInputChanged(); | 251 UserInputChanged(); |
| 256 if (show_tree_ && bb_model_->IsLoaded()) | 252 if (show_tree_ && bb_model_->IsLoaded()) |
| 257 ExpandAndSelect(); | 253 ExpandAndSelect(); |
| 258 GetWidget()->Show(); | 254 GetWidget()->Show(); |
| 259 // Select all the text in the name Textfield. | 255 // Select all the text in the name Textfield. |
| 260 title_tf_->SelectAll(true); | 256 title_tf_->SelectAll(true); |
| 261 // Give focus to the name Textfield. | 257 // Give focus to the name Textfield. |
| 262 title_tf_->RequestFocus(); | 258 title_tf_->RequestFocus(); |
| 263 } | 259 } |
| 264 | 260 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 title_tf_->SetAccessibleName(title_label_->text()); | 307 title_tf_->SetAccessibleName(title_label_->text()); |
| 312 | 308 |
| 313 if (show_tree_) { | 309 if (show_tree_) { |
| 314 tree_view_ = new views::TreeView; | 310 tree_view_ = new views::TreeView; |
| 315 tree_view_->SetRootShown(false); | 311 tree_view_->SetRootShown(false); |
| 316 tree_view_->set_lines_at_root(true); | 312 tree_view_->set_lines_at_root(true); |
| 317 tree_view_->set_context_menu_controller(this); | 313 tree_view_->set_context_menu_controller(this); |
| 318 | 314 |
| 319 new_folder_button_.reset(new views::NativeTextButton(this, | 315 new_folder_button_.reset(new views::NativeTextButton(this, |
| 320 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_BUTTON))); | 316 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_BUTTON))); |
| 317 if (DialogDelegate::UseNewStyle()) |
| 318 views::ApplyChromeStyle(new_folder_button_.get()); |
| 321 new_folder_button_->set_owned_by_client(); | 319 new_folder_button_->set_owned_by_client(); |
| 322 new_folder_button_->SetEnabled(false); | 320 new_folder_button_->SetEnabled(false); |
| 323 } | 321 } |
| 324 | 322 |
| 325 // Yummy layout code. | |
| 326 GridLayout* layout = GridLayout::CreatePanel(this); | 323 GridLayout* layout = GridLayout::CreatePanel(this); |
| 324 if (views::DialogDelegate::UseNewStyle()) |
| 325 layout->SetInsets(gfx::Insets()); |
| 327 SetLayoutManager(layout); | 326 SetLayoutManager(layout); |
| 328 | 327 |
| 329 const int labels_column_set_id = 0; | 328 const int labels_column_set_id = 0; |
| 330 const int single_column_view_set_id = 1; | 329 const int single_column_view_set_id = 1; |
| 331 const int buttons_column_set_id = 2; | 330 const int buttons_column_set_id = 2; |
| 332 | 331 |
| 333 views::ColumnSet* column_set = layout->AddColumnSet(labels_column_set_id); | 332 views::ColumnSet* column_set = layout->AddColumnSet(labels_column_set_id); |
| 334 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 333 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 335 GridLayout::USE_PREF, 0, 0); | 334 GridLayout::USE_PREF, 0, 0); |
| 336 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 335 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
| 337 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 336 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, |
| 338 GridLayout::USE_PREF, 0, 0); | 337 GridLayout::USE_PREF, 0, 0); |
| 339 | 338 |
| 340 column_set = layout->AddColumnSet(single_column_view_set_id); | 339 column_set = layout->AddColumnSet(single_column_view_set_id); |
| 341 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 340 if (views::DialogDelegate::UseNewStyle()) { |
| 342 GridLayout::FIXED, kTreeWidth, 0); | 341 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 342 GridLayout::USE_PREF, 0, 0); |
| 343 } else { |
| 344 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 345 GridLayout::FIXED, 300, 0); |
| 346 } |
| 343 | 347 |
| 344 column_set = layout->AddColumnSet(buttons_column_set_id); | 348 column_set = layout->AddColumnSet(buttons_column_set_id); |
| 345 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, | 349 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, |
| 346 GridLayout::USE_PREF, 0, 0); | 350 GridLayout::USE_PREF, 0, 0); |
| 347 column_set->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | 351 column_set->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); |
| 348 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, | 352 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, |
| 349 GridLayout::USE_PREF, 0, 0); | 353 GridLayout::USE_PREF, 0, 0); |
| 350 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 354 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
| 351 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, | 355 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0, |
| 352 GridLayout::USE_PREF, 0, 0); | 356 GridLayout::USE_PREF, 0, 0); |
| 353 column_set->LinkColumnSizes(0, 2, 4, -1); | 357 column_set->LinkColumnSizes(0, 2, 4, -1); |
| 354 | 358 |
| 355 layout->StartRow(0, labels_column_set_id); | 359 layout->StartRow(0, labels_column_set_id); |
| 356 | |
| 357 layout->AddView(title_label_); | 360 layout->AddView(title_label_); |
| 358 layout->AddView(title_tf_); | 361 layout->AddView(title_tf_); |
| 359 | 362 |
| 360 if (details_.GetNodeType() != BookmarkNode::FOLDER) { | 363 if (details_.GetNodeType() != BookmarkNode::FOLDER) { |
| 361 url_label_ = new views::Label( | 364 url_label_ = new views::Label( |
| 362 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_URL_LABEL)); | 365 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_URL_LABEL)); |
| 363 | 366 |
| 364 url_tf_ = new views::Textfield; | 367 url_tf_ = new views::Textfield; |
| 365 PrefServiceBase* prefs = profile_ ? | 368 PrefServiceBase* prefs = profile_ ? |
| 366 PrefServiceBase::FromBrowserContext(profile_) : | 369 PrefServiceBase::FromBrowserContext(profile_) : |
| 367 NULL; | 370 NULL; |
| 368 url_tf_->SetText(chrome::FormatBookmarkURLForDisplay(url, prefs)); | 371 url_tf_->SetText(chrome::FormatBookmarkURLForDisplay(url, prefs)); |
| 369 url_tf_->SetController(this); | 372 url_tf_->SetController(this); |
| 370 url_tf_->SetAccessibleName(url_label_->text()); | 373 url_tf_->SetAccessibleName(url_label_->text()); |
| 371 | 374 |
| 372 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 375 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM); | 649 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM); |
| 647 } | 650 } |
| 648 return context_menu_model_.get(); | 651 return context_menu_model_.get(); |
| 649 } | 652 } |
| 650 | 653 |
| 651 void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node, | 654 void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node, |
| 652 const string16& title) { | 655 const string16& title) { |
| 653 if (!title.empty()) | 656 if (!title.empty()) |
| 654 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); | 657 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); |
| 655 } | 658 } |
| OLD | NEW |