Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc

Issue 7617006: views/bookmarks: Fix memory leak in BookmarkEditorView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_editor_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/views/bookmarks/bookmark_editor_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/bookmarks/bookmark_utils.h" 12 #include "chrome/browser/bookmarks/bookmark_utils.h"
13 #include "chrome/browser/history/history.h" 13 #include "chrome/browser/history/history.h"
14 #include "chrome/browser/net/url_fixer_upper.h" 14 #include "chrome/browser/net/url_fixer_upper.h"
15 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "grit/chromium_strings.h" 19 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
21 #include "grit/locale_settings.h" 21 #include "grit/locale_settings.h"
22 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "views/background.h" 24 #include "views/background.h"
25 #include "views/controls/button/text_button.h" 25 #include "views/controls/button/text_button.h"
26 #include "views/controls/label.h"
27 #include "views/controls/menu/menu_2.h" 26 #include "views/controls/menu/menu_2.h"
28 #include "views/controls/textfield/textfield.h" 27 #include "views/controls/textfield/textfield.h"
29 #include "views/focus/focus_manager.h" 28 #include "views/focus/focus_manager.h"
30 #include "views/layout/grid_layout.h" 29 #include "views/layout/grid_layout.h"
31 #include "views/layout/layout_constants.h" 30 #include "views/layout/layout_constants.h"
32 #include "views/widget/widget.h" 31 #include "views/widget/widget.h"
33 32
34 using views::Button;
35 using views::ColumnSet;
36 using views::GridLayout; 33 using views::GridLayout;
37 using views::Label; 34
38 using views::Textfield; 35 namespace {
39 36
40 // Background color of text field when URL is invalid. 37 // Background color of text field when URL is invalid.
41 static const SkColor kErrorColor = SkColorSetRGB(0xFF, 0xBC, 0xBC); 38 const SkColor kErrorColor = SkColorSetRGB(0xFF, 0xBC, 0xBC);
42 39
43 // Preferred width of the tree. 40 // Preferred width of the tree.
44 static const int kTreeWidth = 300; 41 const int kTreeWidth = 300;
45 42
46 // ID for various children. 43 // ID for various children.
47 static const int kNewFolderButtonID = 1002; 44 const int kNewFolderButtonID = 1002;
45
46 } // namespace
48 47
49 // static 48 // static
50 void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd, 49 void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd,
51 Profile* profile, 50 Profile* profile,
52 const BookmarkNode* parent, 51 const BookmarkNode* parent,
53 const EditDetails& details, 52 const EditDetails& details,
54 Configuration configuration) { 53 Configuration configuration) {
55 DCHECK(profile); 54 DCHECK(profile);
56 BookmarkEditorView* editor = 55 BookmarkEditorView* editor =
57 new BookmarkEditorView(profile, parent, details, configuration); 56 new BookmarkEditorView(profile, parent, details, configuration);
58 editor->Show(parent_hwnd); 57 editor->Show(parent_hwnd);
59 } 58 }
60 59
61 BookmarkEditorView::BookmarkEditorView( 60 BookmarkEditorView::BookmarkEditorView(
62 Profile* profile, 61 Profile* profile,
63 const BookmarkNode* parent, 62 const BookmarkNode* parent,
64 const EditDetails& details, 63 const EditDetails& details,
65 BookmarkEditor::Configuration configuration) 64 BookmarkEditor::Configuration configuration)
66 : profile_(profile), 65 : profile_(profile),
67 tree_view_(NULL), 66 tree_view_(NULL),
68 new_folder_button_(NULL), 67 new_folder_button_(NULL),
69 url_label_(NULL),
70 title_label_(NULL), 68 title_label_(NULL),
71 parent_(parent), 69 parent_(parent),
72 details_(details), 70 details_(details),
73 running_menu_for_root_(false), 71 running_menu_for_root_(false),
74 show_tree_(configuration == SHOW_TREE) { 72 show_tree_(configuration == SHOW_TREE) {
75 DCHECK(profile); 73 DCHECK(profile);
76 Init(); 74 Init();
77 } 75 }
78 76
79 BookmarkEditorView::~BookmarkEditorView() { 77 BookmarkEditorView::~BookmarkEditorView() {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 views::TreeView* tree_view) { 170 views::TreeView* tree_view) {
173 } 171 }
174 172
175 bool BookmarkEditorView::CanEdit(views::TreeView* tree_view, 173 bool BookmarkEditorView::CanEdit(views::TreeView* tree_view,
176 ui::TreeModelNode* node) { 174 ui::TreeModelNode* node) {
177 // Only allow editting of children of the bookmark bar node and other node. 175 // Only allow editting of children of the bookmark bar node and other node.
178 EditorNode* bb_node = tree_model_->AsNode(node); 176 EditorNode* bb_node = tree_model_->AsNode(node);
179 return (bb_node->parent() && bb_node->parent()->parent()); 177 return (bb_node->parent() && bb_node->parent()->parent());
180 } 178 }
181 179
182 void BookmarkEditorView::ContentsChanged(Textfield* sender, 180 void BookmarkEditorView::ContentsChanged(views::Textfield* sender,
183 const std::wstring& new_contents) { 181 const std::wstring& new_contents) {
184 UserInputChanged(); 182 UserInputChanged();
185 } 183 }
186 184
187 void BookmarkEditorView::ButtonPressed( 185 void BookmarkEditorView::ButtonPressed(views::Button* sender,
188 Button* sender, const views::Event& event) { 186 const views::Event& event) {
189 DCHECK(sender); 187 DCHECK(sender);
190 switch (sender->id()) { 188 switch (sender->id()) {
191 case kNewFolderButtonID: 189 case kNewFolderButtonID:
192 NewFolder(); 190 NewFolder();
193 break; 191 break;
194 192
195 default: 193 default:
196 NOTREACHED(); 194 NOTREACHED();
197 } 195 }
198 } 196 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Because this gets parsed by FixupURL(), it's safe to omit the scheme or 318 // Because this gets parsed by FixupURL(), it's safe to omit the scheme or
321 // trailing slash, and unescape most characters, but we need to not drop any 319 // trailing slash, and unescape most characters, but we need to not drop any
322 // username/password, or unescape anything that changes the meaning. 320 // username/password, or unescape anything that changes the meaning.
323 url_text = net::FormatUrl(url, languages, 321 url_text = net::FormatUrl(url, languages,
324 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, 322 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword,
325 UnescapeRule::SPACES, NULL, NULL, NULL); 323 UnescapeRule::SPACES, NULL, NULL, NULL);
326 } 324 }
327 url_tf_.SetText(UTF16ToWide(url_text)); 325 url_tf_.SetText(UTF16ToWide(url_text));
328 url_tf_.SetController(this); 326 url_tf_.SetController(this);
329 327
330 url_label_ = new views::Label( 328 url_label_.set_parent_owned(false);
Peter Kasting 2011/08/11 18:59:42 This whole system concerns me. We have |url_tf_|
329 url_label_.SetText(
331 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_URL_LABEL))); 330 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_URL_LABEL)));
332 url_tf_.SetAccessibleName(WideToUTF16Hack(url_label_->GetText())); 331 url_tf_.SetAccessibleName(WideToUTF16Hack(url_label_.GetText()));
333 332
334 if (show_tree_) { 333 if (show_tree_) {
335 tree_view_ = new views::TreeView(); 334 tree_view_ = new views::TreeView();
336 tree_view_->set_lines_at_root(true); 335 tree_view_->set_lines_at_root(true);
337 new_folder_button_.reset(new views::NativeTextButton( 336 new_folder_button_.reset(new views::NativeTextButton(
338 this, 337 this,
339 UTF16ToWide(l10n_util::GetStringUTF16( 338 UTF16ToWide(l10n_util::GetStringUTF16(
340 IDS_BOOMARK_EDITOR_NEW_FOLDER_BUTTON)))); 339 IDS_BOOMARK_EDITOR_NEW_FOLDER_BUTTON))));
341 new_folder_button_->set_parent_owned(false); 340 new_folder_button_->set_parent_owned(false);
342 tree_view_->set_context_menu_controller(this); 341 tree_view_->set_context_menu_controller(this);
343 342
344 tree_view_->SetRootShown(false); 343 tree_view_->SetRootShown(false);
345 new_folder_button_->SetEnabled(false); 344 new_folder_button_->SetEnabled(false);
346 new_folder_button_->set_id(kNewFolderButtonID); 345 new_folder_button_->set_id(kNewFolderButtonID);
347 } 346 }
348 347
349 // Yummy layout code. 348 // Yummy layout code.
350 GridLayout* layout = GridLayout::CreatePanel(this); 349 GridLayout* layout = GridLayout::CreatePanel(this);
351 SetLayoutManager(layout); 350 SetLayoutManager(layout);
352 351
353 const int labels_column_set_id = 0; 352 const int labels_column_set_id = 0;
354 const int single_column_view_set_id = 1; 353 const int single_column_view_set_id = 1;
355 const int buttons_column_set_id = 2; 354 const int buttons_column_set_id = 2;
356 355
357 ColumnSet* column_set = layout->AddColumnSet(labels_column_set_id); 356 views::ColumnSet* column_set = layout->AddColumnSet(labels_column_set_id);
358 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 357 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
359 GridLayout::USE_PREF, 0, 0); 358 GridLayout::USE_PREF, 0, 0);
360 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 359 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
361 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 360 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
362 GridLayout::USE_PREF, 0, 0); 361 GridLayout::USE_PREF, 0, 0);
363 362
364 column_set = layout->AddColumnSet(single_column_view_set_id); 363 column_set = layout->AddColumnSet(single_column_view_set_id);
365 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 364 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
366 GridLayout::FIXED, kTreeWidth, 0); 365 GridLayout::FIXED, kTreeWidth, 0);
367 366
(...skipping 10 matching lines...) Expand all
378 377
379 layout->StartRow(0, labels_column_set_id); 378 layout->StartRow(0, labels_column_set_id);
380 379
381 layout->AddView(title_label_); 380 layout->AddView(title_label_);
382 layout->AddView(&title_tf_); 381 layout->AddView(&title_tf_);
383 382
384 if (details_.type != EditDetails::NEW_FOLDER) { 383 if (details_.type != EditDetails::NEW_FOLDER) {
385 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 384 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
386 385
387 layout->StartRow(0, labels_column_set_id); 386 layout->StartRow(0, labels_column_set_id);
388 layout->AddView(url_label_); 387 layout->AddView(&url_label_);
389 layout->AddView(&url_tf_); 388 layout->AddView(&url_tf_);
390 } 389 }
391 390
392 if (show_tree_) { 391 if (show_tree_) {
393 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 392 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
394 layout->StartRow(1, single_column_view_set_id); 393 layout->StartRow(1, single_column_view_set_id);
395 layout->AddView(tree_view_); 394 layout->AddView(tree_view_);
396 } 395 }
397 396
398 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 397 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 EditorNode* editor_node, 640 EditorNode* editor_node,
642 BookmarkExpandedStateTracker::Nodes* expanded_nodes) { 641 BookmarkExpandedStateTracker::Nodes* expanded_nodes) {
643 if (!tree_view_->IsExpanded(editor_node)) 642 if (!tree_view_->IsExpanded(editor_node))
644 return; 643 return;
645 644
646 if (editor_node->value != 0) // The root is 0 645 if (editor_node->value != 0) // The root is 0
647 expanded_nodes->insert(bb_model_->GetNodeByID(editor_node->value)); 646 expanded_nodes->insert(bb_model_->GetNodeByID(editor_node->value));
648 for (int i = 0; i < editor_node->child_count(); ++i) 647 for (int i = 0; i < editor_node->child_count(); ++i)
649 UpdateExpandedNodes(editor_node->GetChild(i), expanded_nodes); 648 UpdateExpandedNodes(editor_node->GetChild(i), expanded_nodes);
650 } 649 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_editor_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698