Commit dcf17fe2 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

macviews: delete Cocoa bookmark secondary UI

This UI was only reachable in !mac_views_browser (last shipped in M66) with
!ShowAllDialogsUsingToolkitViews (last shipped in M65).

Bug: 832676
Change-Id: I3097f0de0b09c28e72c5e3a4c0977739cb0da2cc
Reviewed-on: https://chromium-review.googlesource.com/1151655Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579032}
parent ccb76937
......@@ -9,8 +9,6 @@ assert(is_mac)
translated_xibs = [
"AppMenu.xib",
"BookmarkAllTabs.xib",
"BookmarkNameFolder.xib",
"CookieDetailsView.xib",
"DownloadItem.xib",
"DownloadShelf.xib",
......@@ -24,8 +22,6 @@ translated_xibs = [
if (!mac_views_browser) {
translated_xibs += [
"BookmarkBubble.xib",
"BookmarkEditor.xib",
"CollectedCookies.xib",
"ContentBlockedCookies.xib",
"ContentBlockedDownloads.xib",
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13F1077" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment version="1090" identifier="macosx"/>
<development version="5100" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="BookmarkNameFolderController">
<connections>
<outlet property="nameField_" destination="5" id="11"/>
<outlet property="okButton_" destination="7" id="26"/>
<outlet property="window" destination="1" id="14"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<window title="New Folder" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" visibleAtLaunch="NO" animationBehavior="default" id="1" userLabel="Add Folder">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="408" width="480" height="102"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1028"/>
<view key="contentView" id="2">
<rect key="frame" x="0.0" y="0.0" width="480" height="102"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField verticalHuggingPriority="750" id="5">
<rect key="frame" x="67" y="60" width="393" height="22"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="6">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="25"/>
</connections>
</textField>
<customView id="17" customClass="GTMWidthBasedTweaker">
<rect key="frame" x="260" y="0.0" width="220" height="52"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<subviews>
<button verticalHuggingPriority="750" id="7">
<rect key="frame" x="110" y="12" width="96" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="push" title="^IDS_APP_OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="8">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<connections>
<action selector="ok:" target="-2" id="13"/>
</connections>
</button>
<button verticalHuggingPriority="750" id="9">
<rect key="frame" x="14" y="12" width="96" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="push" title="^IDS_APP_CANCEL" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="10">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent">.</string>
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</buttonCell>
<connections>
<action selector="cancel:" target="-2" id="12"/>
</connections>
</button>
</subviews>
</customView>
<customView id="18" customClass="GTMWidthBasedTweaker">
<rect key="frame" x="0.0" y="42" width="65" height="57"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField verticalHuggingPriority="750" id="3">
<rect key="frame" x="17" y="20" width="45" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="^IDS_BOOKMARK_BAR_EDIT_FOLDER_LABEL" id="4">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="viewToResize_" destination="1" id="19"/>
<outlet property="viewToSlideAndResize_" destination="5" id="20"/>
</connections>
</customView>
</subviews>
</view>
</window>
<customObject id="15" customClass="ChromeUILocalizer"/>
<customObject id="21" customClass="GTMUILocalizerAndLayoutTweaker">
<connections>
<outlet property="localizer_" destination="15" id="22"/>
<outlet property="uiObject_" destination="1" id="23"/>
</connections>
</customObject>
</objects>
</document>
......@@ -80,8 +80,6 @@ jumbo_split_static_library("ui") {
"cocoa/background_gradient_view.mm",
"cocoa/base_bubble_controller.h",
"cocoa/base_bubble_controller.mm",
"cocoa/bookmarks/bookmark_all_tabs_controller.h",
"cocoa/bookmarks/bookmark_all_tabs_controller.mm",
"cocoa/bookmarks/bookmark_bar_bridge.h",
"cocoa/bookmarks/bookmark_bar_bridge.mm",
"cocoa/bookmarks/bookmark_bar_constants.h",
......@@ -102,8 +100,6 @@ jumbo_split_static_library("ui") {
"cocoa/bookmarks/bookmark_bar_toolbar_view.mm",
"cocoa/bookmarks/bookmark_bar_view_cocoa.h",
"cocoa/bookmarks/bookmark_bar_view_cocoa.mm",
"cocoa/bookmarks/bookmark_bubble_controller.h",
"cocoa/bookmarks/bookmark_bubble_controller.mm",
"cocoa/bookmarks/bookmark_bubble_observer_cocoa.h",
"cocoa/bookmarks/bookmark_bubble_observer_cocoa.mm",
"cocoa/bookmarks/bookmark_bar_util.h",
......@@ -115,16 +111,10 @@ jumbo_split_static_library("ui") {
"cocoa/bookmarks/bookmark_context_menu_cocoa_controller.h",
"cocoa/bookmarks/bookmark_context_menu_cocoa_controller.mm",
"cocoa/bookmarks/bookmark_drag_drop_cocoa.mm",
"cocoa/bookmarks/bookmark_editor_base_controller.h",
"cocoa/bookmarks/bookmark_editor_base_controller.mm",
"cocoa/bookmarks/bookmark_editor_controller.h",
"cocoa/bookmarks/bookmark_editor_controller.mm",
"cocoa/bookmarks/bookmark_folder_target.h",
"cocoa/bookmarks/bookmark_folder_target.mm",
"cocoa/bookmarks/bookmark_model_observer_for_cocoa.h",
"cocoa/bookmarks/bookmark_model_observer_for_cocoa.mm",
"cocoa/bookmarks/bookmark_name_folder_controller.h",
"cocoa/bookmarks/bookmark_name_folder_controller.mm",
"cocoa/bookmarks/bookmark_tree_browser_cell.h",
"cocoa/bookmarks/bookmark_tree_browser_cell.mm",
"cocoa/browser/exclusive_access_controller_views.h",
......@@ -207,8 +197,6 @@ jumbo_split_static_library("ui") {
"cocoa/dev_tools_controller.mm",
"cocoa/device_chooser_content_view_cocoa.h",
"cocoa/device_chooser_content_view_cocoa.mm",
"cocoa/dialog_text_field_editor.h",
"cocoa/dialog_text_field_editor.mm",
"cocoa/download/background_theme.h",
"cocoa/download/background_theme.mm",
"cocoa/download/download_danger_prompt_impl.cc",
......@@ -2574,14 +2562,6 @@ jumbo_split_static_library("ui") {
# are obsolete before mac_views_browser will ever ship, so they aren't
# linked in at all.
sources -= [
"cocoa/bookmarks/bookmark_all_tabs_controller.h",
"cocoa/bookmarks/bookmark_all_tabs_controller.mm",
"cocoa/bookmarks/bookmark_bubble_controller.h",
"cocoa/bookmarks/bookmark_bubble_controller.mm",
"cocoa/bookmarks/bookmark_editor_base_controller.h",
"cocoa/bookmarks/bookmark_editor_base_controller.mm",
"cocoa/bookmarks/bookmark_editor_controller.h",
"cocoa/bookmarks/bookmark_editor_controller.mm",
"cocoa/constrained_web_dialog_delegate_mac.mm",
"cocoa/content_settings/blocked_plugin_bubble_controller.h",
"cocoa/content_settings/blocked_plugin_bubble_controller.mm",
......
// Copyright (c) 2010 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_COCOA_BOOKMARKS_BOOKMARK_ALL_TABS_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_ALL_TABS_CONTROLLER_H_
#include <utility>
#include <vector>
#include "base/strings/string16.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.h"
// A list of pairs containing the name and URL associated with each
// currently active tab in the active browser window.
typedef std::pair<base::string16, GURL> ActiveTabNameURLPair;
typedef std::vector<ActiveTabNameURLPair> ActiveTabsNameURLPairVector;
// A controller for the Bookmark All Tabs sheet which is presented upon
// selecting the Bookmark All Tabs... menu item shown by the contextual
// menu in the bookmarks bar.
@interface BookmarkAllTabsController : BookmarkEditorBaseController {
@private
ActiveTabsNameURLPairVector activeTabPairsVector_;
}
- (id)initWithParentWindow:(NSWindow*)parentWindow
profile:(Profile*)profile
parent:(const bookmarks::BookmarkNode*)parent
url:(const GURL&)url
title:(const base::string16&)title
configuration:(BookmarkEditor::Configuration)configuration;
@end
@interface BookmarkAllTabsController(TestingAPI)
// Initializes the list of all tab names and URLs. Overridden by unit test
// to provide canned test data.
- (void)UpdateActiveTabPairs;
// Provides testing access to tab pairs list.
- (ActiveTabsNameURLPairVector*)activeTabPairsVector;
@end
#endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_ALL_TABS_CONTROLLER_H_
// 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.
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller.h"
#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util_mac.h"
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
using content::WebContents;
@implementation BookmarkAllTabsController
- (id)initWithParentWindow:(NSWindow*)parentWindow
profile:(Profile*)profile
parent:(const BookmarkNode*)parent
url:(const GURL&)url
title:(const base::string16&)title
configuration:(BookmarkEditor::Configuration)configuration {
NSString* nibName = @"BookmarkAllTabs";
if ((self = [super initWithParentWindow:parentWindow
nibName:nibName
profile:profile
parent:parent
url:url
title:title
configuration:configuration])) {
}
return self;
}
- (void)awakeFromNib {
[self setInitialName:
l10n_util::GetNSStringWithFixup(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME)];
[super awakeFromNib];
}
#pragma mark Bookmark Editing
- (void)UpdateActiveTabPairs {
activeTabPairsVector_.clear();
Browser* browser = chrome::GetLastActiveBrowser();
const int tabCount = browser->tab_strip_model()->count();
for (int i = 0; i < tabCount; ++i) {
WebContents* contents = browser->tab_strip_model()->GetWebContentsAt(i);
ActiveTabNameURLPair tabPair(contents->GetTitle(), contents->GetURL());
activeTabPairsVector_.push_back(tabPair);
}
}
// Called by -[BookmarkEditorBaseController ok:]. Creates the container
// folder for the tabs and then the bookmarks in that new folder.
// Returns a BOOL as an NSNumber indicating that the commit may proceed.
- (NSNumber*)didCommit {
const BookmarkNode* newParentNode = [self selectedNode];
if (!newParentNode)
return [NSNumber numberWithBool:NO];
int newIndex = newParentNode->child_count();
// Create the new folder which will contain all of the tab URLs.
NSString* newFolderName = [self displayName];
base::string16 newFolderString = base::SysNSStringToUTF16(newFolderName);
BookmarkModel* model = [self bookmarkModel];
const BookmarkNode* newFolder = model->AddFolder(newParentNode, newIndex,
newFolderString);
// Get a list of all open tabs, create nodes for them, and add
// to the new folder node.
[self UpdateActiveTabPairs];
int i = 0;
for (ActiveTabsNameURLPairVector::const_iterator it =
activeTabPairsVector_.begin();
it != activeTabPairsVector_.end(); ++it, ++i) {
model->AddURL(newFolder, i, it->first, it->second);
}
return [NSNumber numberWithBool:YES];
}
- (ActiveTabsNameURLPairVector*)activeTabPairsVector {
return &activeTabPairsVector_;
}
@end // BookmarkAllTabsController
// 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.
#import <Cocoa/Cocoa.h>
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller.h"
#include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
#include "chrome/test/base/testing_profile.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
using base::ASCIIToUTF16;
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
@interface BookmarkAllTabsControllerOverride : BookmarkAllTabsController
@end
@implementation BookmarkAllTabsControllerOverride
- (void)UpdateActiveTabPairs {
ActiveTabsNameURLPairVector* activeTabPairsVector =
[self activeTabPairsVector];
activeTabPairsVector->clear();
activeTabPairsVector->push_back(
ActiveTabNameURLPair(ASCIIToUTF16("at-0"), GURL("http://at-0.com")));
activeTabPairsVector->push_back(
ActiveTabNameURLPair(ASCIIToUTF16("at-1"), GURL("http://at-1.com")));
activeTabPairsVector->push_back(
ActiveTabNameURLPair(ASCIIToUTF16("at-2"), GURL("http://at-2.com")));
}
@end
class BookmarkAllTabsControllerTest : public CocoaProfileTest {
public:
const BookmarkNode* parent_node_;
BookmarkAllTabsControllerOverride* controller_;
const BookmarkNode* folder_a_;
void CreateModel() {
BookmarkModel* model =
BookmarkModelFactory::GetForBrowserContext(profile());
const BookmarkNode* root = model->bookmark_bar_node();
folder_a_ = model->AddFolder(root, 0, ASCIIToUTF16("a"));
model->AddURL(folder_a_, 0, ASCIIToUTF16("a-0"), GURL("http://a-0.com"));
model->AddURL(folder_a_, 1, ASCIIToUTF16("a-1"), GURL("http://a-1.com"));
model->AddURL(folder_a_, 2, ASCIIToUTF16("a-2"), GURL("http://a-2.com"));
}
virtual BookmarkAllTabsControllerOverride* CreateController() {
return [[BookmarkAllTabsControllerOverride alloc]
initWithParentWindow:test_window()
profile:profile()
parent:folder_a_
url:GURL()
title:base::string16()
configuration:BookmarkEditor::SHOW_TREE];
}
void SetUp() override {
CocoaProfileTest::SetUp();
ASSERT_TRUE(profile());
CreateModel();
controller_ = CreateController();
[controller_ runAsModalSheet];
}
void TearDown() override {
controller_ = NULL;
CocoaProfileTest::TearDown();
}
};
TEST_F(BookmarkAllTabsControllerTest, BookmarkAllTabs) {
// OK button should always be enabled.
EXPECT_TRUE([controller_ okButtonEnabled]);
[controller_ selectTestNodeInBrowser:folder_a_];
[controller_ setDisplayName:@"ALL MY TABS"];
[controller_ ok:nil];
EXPECT_EQ(4, folder_a_->child_count());
const BookmarkNode* folderChild = folder_a_->GetChild(3);
EXPECT_EQ(folderChild->GetTitle(), ASCIIToUTF16("ALL MY TABS"));
EXPECT_EQ(3, folderChild->child_count());
}
......@@ -38,11 +38,9 @@
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_model_observer_for_cocoa.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/menu_button.h"
......
// 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_COCOA_BOOKMARKS_BOOKMARK_BUBBLE_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BUBBLE_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include <memory>
#include "base/mac/availability.h"
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_model_observer_for_cocoa.h"
#import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
#import "chrome/browser/ui/cocoa/omnibox_decoration_bubble_controller.h"
#import "ui/base/cocoa/touch_bar_forward_declarations.h"
@class BookmarkBubbleController;
@class BubbleSyncPromoController;
@class DialogTextFieldEditor;
namespace bookmarks {
class BookmarkBubbleObserver;
class BookmarkModel;
class BookmarkNode;
class ManagedBookmarkService;
}
// Controller for the bookmark bubble. The bookmark bubble is a
// bubble that pops up when clicking on the STAR next to the URL to
// add or remove it as a bookmark. This bubble allows for editing of
// the bookmark in various ways (name, folder, etc.)
@interface BookmarkBubbleController
: OmniboxDecorationBubbleController<NSTouchBarDelegate,
HasWeakBrowserPointer> {
@private
// |managed_|, |model_| and |node_| are weak and owned by the current
// browser's profile.
bookmarks::ManagedBookmarkService* managedBookmarkService_; // weak
bookmarks::BookmarkModel* model_; // weak
const bookmarks::BookmarkNode* node_; // weak
// Inform the observer when the bubble is shown or closed.
bookmarks::BookmarkBubbleObserver* bookmarkBubbleObserver_; // weak
BOOL alreadyBookmarked_;
// Ping me when the bookmark model changes out from under us.
std::unique_ptr<BookmarkModelObserverForCocoa> bookmarkObserver_;
// Sync promo controller, if the sync promo is displayed.
base::scoped_nsobject<BubbleSyncPromoController> syncPromoController_;
// Field editor for |nameTextField_|.
base::scoped_nsobject<DialogTextFieldEditor> textFieldEditor_;
IBOutlet NSTextField* bigTitle_; // "Bookmark" or "Bookmark Added!"
IBOutlet NSTextField* nameTextField_;
IBOutlet NSPopUpButton* folderPopUpButton_;
IBOutlet NSView* syncPromoPlaceholder_;
IBOutlet NSView* fieldLabelsContainer_;
IBOutlet NSView* trailingButtonContainer_;
}
@property(readonly, nonatomic) const bookmarks::BookmarkNode* node;
// |node| is the bookmark node we edit in this bubble.
// |alreadyBookmarked| tells us if the node was bookmarked before the
// user clicked on the star. (if NO, this is a brand new bookmark).
// The owner of this object is responsible for showing the bubble if
// it desires it to be visible on the screen. It is not shown by the
// init routine. Closing of the window happens implicitly on dealloc.
- (id)initWithParentWindow:(NSWindow*)parentWindow
bubbleObserver:(bookmarks::BookmarkBubbleObserver*)bubbleObserver
managed:(bookmarks::ManagedBookmarkService*)managed
model:(bookmarks::BookmarkModel*)model
node:(const bookmarks::BookmarkNode*)node
alreadyBookmarked:(BOOL)alreadyBookmarked;
// Actions for buttons in the dialog.
- (IBAction)ok:(id)sender;
- (IBAction)remove:(id)sender;
- (IBAction)cancel:(id)sender;
// These actions send a -editBookmarkNode: action up the responder chain.
- (IBAction)edit:(id)sender;
- (IBAction)folderChanged:(id)sender;
// Overridden to customize the touch bar.
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macos(10.12.2));
@end
// Exposed only for unit testing.
@interface BookmarkBubbleController (ExposedForUnitTesting)
@property(nonatomic, readonly) NSView* syncPromoPlaceholder;
@property(nonatomic, readonly)
bookmarks::BookmarkBubbleObserver* bookmarkBubbleObserver;
- (void)addFolderNodes:(const bookmarks::BookmarkNode*)parent
toPopUpButton:(NSPopUpButton*)button
indentation:(int)indentation;
- (void)setTitle:(NSString*)title
parentFolder:(const bookmarks::BookmarkNode*)parent;
- (void)setParentFolderSelection:(const bookmarks::BookmarkNode*)parent;
+ (NSString*)chooseAnotherFolderString;
- (NSPopUpButton*)folderPopUpButton;
@end
#endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BUBBLE_CONTROLLER_H_
// 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_COCOA_BOOKMARKS_BOOKMARK_EDITOR_BASE_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_EDITOR_BASE_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include <memory>
#include "base/mac/availability.h"
#include "base/mac/scoped_nsobject.h"
#include "chrome/browser/ui/bookmarks/bookmark_editor.h"
#include "components/bookmarks/browser/bookmark_expanded_state_tracker.h"
#import "ui/base/cocoa/touch_bar_forward_declarations.h"
class BookmarkEditorBaseControllerBridge;
@class BookmarkTreeBrowserCell;
namespace bookmarks {
class BookmarkModel;
}
// A base controller class for bookmark creation and editing dialogs which
// present the current bookmark folder structure in a tree view. Do not
// instantiate this controller directly -- use one of its derived classes.
// NOTE: If a derived class is intended to be dispatched via the
// BookmarkEditor::Show static function found in the accompanying
// implementation, that function will need to be update.
@interface BookmarkEditorBaseController
: NSWindowController<NSOutlineViewDelegate, NSTouchBarDelegate> {
@private
IBOutlet NSButton* newFolderButton_;
IBOutlet NSButton* okButton_; // Used for unit testing only.
IBOutlet NSTreeController* folderTreeController_;
IBOutlet NSOutlineView* folderTreeView_;
NSWindow* parentWindow_; // weak
Profile* profile_; // weak
const bookmarks::BookmarkNode* parentNode_; // weak; owned by the model
GURL url_; // This and title_ are only used for new urls.
base::string16 title_;
BookmarkEditor::Configuration configuration_;
NSString* initialName_;
NSString* displayName_; // Bound to a text field in the dialog.
BOOL creatingNewFolders_; // True while in createNewFolders.
// An array of BookmarkFolderInfo where each item describes a folder in the
// BookmarkNode structure.
base::scoped_nsobject<NSArray> folderTreeArray_;
// Bound to the table view giving a path to the current selections, of which
// there should only ever be one.
base::scoped_nsobject<NSArray> tableSelectionPaths_;
// C++ bridge object that observes the BookmarkModel for me.
std::unique_ptr<BookmarkEditorBaseControllerBridge> observer_;
}
@property(nonatomic, copy) NSString* initialName;
@property(nonatomic, copy) NSString* displayName;
@property(nonatomic, retain, readonly) NSArray* folderTreeArray;
@property(nonatomic, copy) NSArray* tableSelectionPaths;
// Designated initializer. Derived classes should call through to this init.
// |url| and |title| are only used for BookmarkNode::Type::NEW_URL.
- (id)initWithParentWindow:(NSWindow*)parentWindow
nibName:(NSString*)nibName
profile:(Profile*)profile
parent:(const bookmarks::BookmarkNode*)parent
url:(const GURL&)url
title:(const base::string16&)title
configuration:(BookmarkEditor::Configuration)configuration;
- (void)windowWillClose:(NSNotification*)notification;
// Override to customize the touch bar.
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macos(10.12.2));
// Run the bookmark editor as a modal sheet. Does not block.
- (void)runAsModalSheet;
// Create a new folder at the end of the selected parent folder, give it
// an untitled name, and put it into editing mode.
- (IBAction)newFolder:(id)sender;
// The cancel action will dismiss the dialog. Derived classes which
// override cancel:, must call this after accessing any dialog-related
// data.
- (IBAction)cancel:(id)sender;
// The OK action will dismiss the dialog. This action is bound
// to the OK button of a dialog which presents a tree view of a profile's
// folder hierarchy and allows the creation of new folders within that tree.
// When the OK button is pressed, this function will: 1) call the derived
// class's -[willCommit] function, 2) create any new folders created by
// the user while the dialog is presented, 3) call the derived class's
// -[didCommit] function, and then 4) dismiss the dialog. At least one
// of -[willCommit] and -[didCommit] must be provided by the derived class
// and should return a NSNumber containing a BOOL or nil ('nil' means YES)
// indicating if the operation should be allowed to continue.
// Note: A derived class should not override the ok: action.
- (IBAction)ok:(id)sender;
// Methods for use by derived classes only.
// Determine and returns the rightmost selected/highlighted element (node)
// in the bookmark tree view if the tree view is showing, otherwise returns
// the original |parentNode_|. If the tree view is showing but nothing is
// selected then the root node is returned.
- (const bookmarks::BookmarkNode*)selectedNode;
// Expands the set of BookmarkNodes in |nodes|.
- (void)expandNodes:(
const bookmarks::BookmarkExpandedStateTracker::Nodes&)nodes;
// Returns the set of expanded BookmarkNodes.
- (bookmarks::BookmarkExpandedStateTracker::Nodes)getExpandedNodes;
// Select/highlight the given node within the browser tree view. If the
// node is nil then select the bookmark bar node. Exposed for unit test.
- (void)selectNodeInBrowser:(const bookmarks::BookmarkNode*)node;
// Notifications called when the BookmarkModel changes out from under me.
- (void)nodeRemoved:(const bookmarks::BookmarkNode*)node
fromParent:(const bookmarks::BookmarkNode*)parent;
- (void)modelChangedPreserveSelection:(BOOL)preserve;
// Determines if the ok button should be enabled, can be overridden.
- (BOOL)okEnabled;
// Accessors
- (bookmarks::BookmarkModel*)bookmarkModel;
- (Profile*)profile;
- (const bookmarks::BookmarkNode*)parentNode;
- (const GURL&)url;
- (const base::string16&)title;
@end
// Describes the profile's bookmark folder structure: the folder name, the
// original BookmarkNode pointer (if the folder already exists), a BOOL
// indicating if the folder is new (meaning: created during this session
// but not yet committed to the bookmark structure), and an NSArray of
// child folder BookmarkFolderInfo's following this same structure.
@interface BookmarkFolderInfo : NSObject {
@private
NSString* folderName_;
const bookmarks::BookmarkNode* folderNode_; // weak
NSMutableArray* children_;
BOOL newFolder_;
}
@property(nonatomic, copy) NSString* folderName;
@property(nonatomic, assign) const bookmarks::BookmarkNode* folderNode;
@property(nonatomic, retain) NSMutableArray* children;
@property(nonatomic, assign) BOOL newFolder;
// Convenience creator for adding a new folder to the editor's bookmark
// structure. This folder will be added to the bookmark model when the
// user accepts the dialog. |folderName| must be provided.
+ (id)bookmarkFolderInfoWithFolderName:(NSString*)folderName;
// Designated initializer. |folderName| must be provided. For folders which
// already exist in the bookmark model, |folderNode| and |children| (if any
// children are already attached to this folder) must be provided and
// |newFolder| should be NO. For folders which the user has added during
// this session and which have not been committed yet, |newFolder| should be
// YES and |folderNode| and |children| should be NULL/nil.
- (id)initWithFolderName:(NSString*)folderName
folderNode:(const bookmarks::BookmarkNode*)folderNode
children:(NSMutableArray*)children
newFolder:(BOOL)newFolder;
// Convenience creator used during construction of the editor's bookmark
// structure. |folderName| and |folderNode| must be provided. |children|
// is optional. Private: exposed here for unit testing purposes.
+ (id)bookmarkFolderInfoWithFolderName:(NSString*)folderName
folderNode:
(const bookmarks::BookmarkNode*)folderNode
children:(NSMutableArray*)children;
@end
@interface BookmarkEditorBaseController(TestingAPI)
@property(nonatomic, readonly) BOOL okButtonEnabled;
// Create any newly added folders. New folders are nodes in folderTreeArray
// which are marked as being new (i.e. their kFolderTreeNewFolderKey
// dictionary item is YES). This is called by -[ok:].
- (void)createNewFolders;
// Select the given bookmark node within the tree view.
- (void)selectTestNodeInBrowser:(const bookmarks::BookmarkNode*)node;
// Return the dictionary for the folder selected in the tree.
- (BookmarkFolderInfo*)selectedFolder;
@end
#endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_EDITOR_BASE_CONTROLLER_H_
// Copyright (c) 2011 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_COCOA_BOOKMARKS_BOOKMARK_EDITOR_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_EDITOR_CONTROLLER_H_
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_base_controller.h"
@class DialogTextFieldEditor;
// A controller for the bookmark editor, opened by 1) Edit... from the
// context menu of a bookmark button, and 2) Bookmark this Page...'s Edit
// button.
@interface BookmarkEditorController : BookmarkEditorBaseController {
@private
const bookmarks::BookmarkNode* node_; // weak; owned by the model
base::scoped_nsobject<NSString> initialUrl_;
NSString* displayURL_; // Bound to a text field in the dialog.
IBOutlet NSTextField* urlField_;
IBOutlet NSTextField* nameTextField_;
// Field editor for |urlField_| and |nameTextField_|.
base::scoped_nsobject<DialogTextFieldEditor> touchBarFieldEditor_;
}
@property(nonatomic, copy) NSString* displayURL;
- (id)initWithParentWindow:(NSWindow*)parentWindow
profile:(Profile*)profile
parent:(const bookmarks::BookmarkNode*)parent
node:(const bookmarks::BookmarkNode*)node
url:(const GURL&)url
title:(const base::string16&)title
configuration:(BookmarkEditor::Configuration)configuration;
@end
@interface BookmarkEditorController (UnitTesting)
- (NSColor *)urlFieldColor;
@end
#endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_EDITOR_CONTROLLER_H_
// Copyright (c) 2011 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.
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h"
#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
#import "chrome/browser/ui/cocoa/dialog_text_field_editor.h"
#include "chrome/common/chrome_features.h"
#include "components/bookmarks/browser/bookmark_expanded_state_tracker.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/url_formatter/url_fixer.h"
#include "components/user_prefs/user_prefs.h"
using bookmarks::BookmarkExpandedStateTracker;
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
@interface BookmarkEditorController (Private)
// Grab the url from the text field and convert.
- (GURL)GURLFromUrlField;
@end
@implementation BookmarkEditorController
@synthesize displayURL = displayURL_;
+ (NSSet*)keyPathsForValuesAffectingOkEnabled {
return [NSSet setWithObject:@"displayURL"];
}
- (id)initWithParentWindow:(NSWindow*)parentWindow
profile:(Profile*)profile
parent:(const BookmarkNode*)parent
node:(const BookmarkNode*)node
url:(const GURL&)url
title:(const base::string16&)title
configuration:(BookmarkEditor::Configuration)configuration {
if ((self = [super initWithParentWindow:parentWindow
nibName:@"BookmarkEditor"
profile:profile
parent:parent
url:url
title:title
configuration:configuration])) {
// "Add Page..." has no "node" so this may be NULL.
node_ = node;
touchBarFieldEditor_.reset([[DialogTextFieldEditor alloc] init]);
}
return self;
}
- (void)dealloc {
[displayURL_ release];
[super dealloc];
}
- (void)awakeFromNib {
NSTextFieldCell* nameFieldCell_ = [nameTextField_ cell];
[nameFieldCell_ setUsesSingleLineMode:YES];
// Set text fields to match our bookmark. If the node is NULL we arrived here
// from an "Add Page..." item in a context menu.
if (node_) {
[self setInitialName:base::SysUTF16ToNSString(node_->GetTitle())];
base::string16 urlString =
chrome::FormatBookmarkURLForDisplay(node_->url());
initialUrl_.reset([base::SysUTF16ToNSString(urlString) retain]);
} else {
GURL url = [self url];
[self setInitialName:base::SysUTF16ToNSString([self title])];
if (url.is_valid())
initialUrl_.reset([[NSString stringWithUTF8String:url.spec().c_str()]
retain]);
}
[self setDisplayURL:initialUrl_];
[super awakeFromNib];
[self expandNodes:
[self bookmarkModel]->expanded_state_tracker()->GetExpandedNodes()];
}
- (void)windowWillClose:(NSNotification*)notification {
[touchBarFieldEditor_ setFieldEditor:NO];
touchBarFieldEditor_.reset();
[super windowWillClose:notification];
}
- (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj {
if (!base::FeatureList::IsEnabled(features::kDialogTouchBar))
return nil;
if (obj == urlField_ || obj == nameTextField_)
return touchBarFieldEditor_.get();
return nil;
}
- (void)nodeRemoved:(const BookmarkNode*)node
fromParent:(const BookmarkNode*)parent
{
// Be conservative; it is needed (e.g. "Add Page...")
node_ = NULL;
[self cancel:self];
}
#pragma mark Bookmark Editing
// If possible, return a valid GURL from the URL text field.
- (GURL)GURLFromUrlField {
NSString* url = [self displayURL];
return url_formatter::FixupURL([url UTF8String], std::string());
}
// Enable the OK button if there is a valid URL.
- (BOOL)okEnabled {
BOOL okEnabled = NO;
if ([[self displayURL] length]) {
GURL newURL = [self GURLFromUrlField];
okEnabled = (newURL.is_valid()) ? YES : NO;
}
if (okEnabled)
[urlField_ setBackgroundColor:[NSColor whiteColor]];
else
[urlField_ setBackgroundColor:[NSColor colorWithCalibratedRed:1.0
green:0.67
blue:0.67
alpha:1.0]];
return okEnabled;
}
// The bookmark's URL is assumed to be valid (otherwise the OK button
// should not be enabled). Previously existing bookmarks for which the
// parent has not changed are updated in-place. Those for which the parent
// has changed are removed with a new node created under the new parent.
// Called by -[BookmarkEditorBaseController ok:].
- (NSNumber*)didCommit {
NSString* name = [[self displayName] stringByTrimmingCharactersInSet:
[NSCharacterSet newlineCharacterSet]];
base::string16 newTitle = base::SysNSStringToUTF16(name);
const BookmarkNode* newParentNode = [self selectedNode];
GURL newURL = [self GURLFromUrlField];
if (!newURL.is_valid()) {
// Shouldn't be reached -- OK button should be disabled if not valid!
NOTREACHED();
return [NSNumber numberWithBool:NO];
}
// Determine where the new/replacement bookmark is to go.
BookmarkModel* model = [self bookmarkModel];
// If there was an old node then we update the node, and move it to its new
// parent if the parent has changed (rather than deleting it from the old
// parent and adding to the new -- which also prevents the 'poofing' that
// occurs when a node is deleted).
if (node_) {
model->SetURL(node_, newURL);
model->SetTitle(node_, newTitle);
const BookmarkNode* oldParentNode = [self parentNode];
if (newParentNode != oldParentNode)
model->Move(node_, newParentNode, newParentNode->child_count());
} else {
// Otherwise, add a new bookmark at the end of the newly selected folder.
model->AddURL(newParentNode, newParentNode->child_count(), newTitle,
newURL);
}
// Update the expanded state.
BookmarkExpandedStateTracker::Nodes expanded_nodes = [self getExpandedNodes];
[self bookmarkModel]->expanded_state_tracker()->
SetExpandedNodes(expanded_nodes);
return [NSNumber numberWithBool:YES];
}
- (NSColor *)urlFieldColor {
return [urlField_ backgroundColor];
}
@end // BookmarkEditorController
// Copyright (c) 2011 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_COCOA_BOOKMARKS_BOOKMARK_NAME_FOLDER_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_NAME_FOLDER_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include <memory>
#include "base/mac/scoped_nsobject.h"
class BookmarkModelObserverForCocoa;
class Profile;
namespace bookmarks {
class BookmarkNode;
}
// A controller for dialog to let the user create a new folder or
// rename an existing folder. Accessible from a context menu on a
// bookmark button or the bookmark bar.
@interface BookmarkNameFolderController : NSWindowController {
@private
IBOutlet NSTextField* nameField_;
IBOutlet NSButton* okButton_;
NSWindow* parentWindow_; // weak
Profile* profile_; // weak
// Weak; owned by the model. Can be NULL (see below). Either node_
// is non-NULL (renaming a folder), or parent_ is non-NULL (adding a
// new one).
const bookmarks::BookmarkNode* node_;
const bookmarks::BookmarkNode* parent_;
int newIndex_;
base::scoped_nsobject<NSString> initialName_;
// Ping me when things change out from under us.
std::unique_ptr<BookmarkModelObserverForCocoa> observer_;
}
// Use the 1st initializer for a "rename existing folder" request.
//
// Use the 2nd initializer for an "add folder" request. If creating a
// new folder |parent| and |newIndex| specify where to put the new
// node.
- (id)initWithParentWindow:(NSWindow*)window
profile:(Profile*)profile
node:(const bookmarks::BookmarkNode*)node;
- (id)initWithParentWindow:(NSWindow*)window
profile:(Profile*)profile
parent:(const bookmarks::BookmarkNode*)parent
newIndex:(int)newIndex;
- (void)runAsModalSheet;
- (IBAction)cancel:(id)sender;
- (IBAction)ok:(id)sender;
@end
@interface BookmarkNameFolderController(TestingAPI)
- (NSString*)folderName;
- (void)setFolderName:(NSString*)name;
- (NSButton*)okButton;
@end
#endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_NAME_FOLDER_CONTROLLER_H_
// 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.
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h"
#include "base/mac/bundle_locations.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/cocoa/bookmarks/bookmark_model_observer_for_cocoa.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
@implementation BookmarkNameFolderController
// Common initializer (private).
- (id)initWithParentWindow:(NSWindow*)window
profile:(Profile*)profile
node:(const BookmarkNode*)node
parent:(const BookmarkNode*)parent
newIndex:(int)newIndex {
NSString* nibpath = [base::mac::FrameworkBundle()
pathForResource:@"BookmarkNameFolder"
ofType:@"nib"];
if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
parentWindow_ = window;
profile_ = profile;
node_ = node;
parent_ = parent;
newIndex_ = newIndex;
if (parent) {
DCHECK_LE(newIndex, parent->child_count());
}
if (node_) {
initialName_.reset([base::SysUTF16ToNSString(node_->GetTitle()) retain]);
} else {
NSString* newString =
l10n_util::GetNSStringWithFixup(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME);
initialName_.reset([newString retain]);
}
}
return self;
}
- (id)initWithParentWindow:(NSWindow*)window
profile:(Profile*)profile
node:(const BookmarkNode*)node {
DCHECK(node);
return [self initWithParentWindow:window
profile:profile
node:node
parent:nil
newIndex:0];
}
- (id)initWithParentWindow:(NSWindow*)window
profile:(Profile*)profile
parent:(const BookmarkNode*)parent
newIndex:(int)newIndex {
DCHECK(parent);
return [self initWithParentWindow:window
profile:profile
node:nil
parent:parent
newIndex:newIndex];
}
- (void)awakeFromNib {
[nameField_ setStringValue:initialName_.get()];
[[nameField_ cell] setUsesSingleLineMode:YES];
[okButton_ setTitle:l10n_util::GetNSStringWithFixup(node_ ? IDS_SAVE :
IDS_ADD)];
}
- (void)runAsModalSheet {
// Ping me when things change out from under us.
observer_.reset(new BookmarkModelObserverForCocoa(
BookmarkModelFactory::GetForBrowserContext(profile_), ^{
[self cancel:nil];
}));
observer_->StartObservingNode(node_);
[NSApp beginSheet:[self window]
modalForWindow:parentWindow_
modalDelegate:self
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
contextInfo:nil];
}
- (IBAction)cancel:(id)sender {
[NSApp endSheet:[self window]];
}
- (IBAction)ok:(id)sender {
NSString* name = [nameField_ stringValue];
if ([name length] == 0)
name = l10n_util::GetNSStringWithFixup(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME);
BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile_);
if (node_) {
model->SetTitle(node_, base::SysNSStringToUTF16(name));
} else {
model->AddFolder(parent_,
newIndex_,
base::SysNSStringToUTF16(name));
}
[NSApp endSheet:[self window]];
}
- (void)didEndSheet:(NSWindow*)sheet
returnCode:(int)returnCode
contextInfo:(void*)contextInfo {
[[self window] orderOut:self];
observer_.reset(NULL);
[self autorelease];
}
- (NSString*)folderName {
return [nameField_ stringValue];
}
- (void)setFolderName:(NSString*)name {
[nameField_ setStringValue:name];
}
- (NSButton*)okButton {
return okButton_;
}
@end // BookmarkNameFolderController
// 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.
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h"
#include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
#include "chrome/test/base/testing_profile.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
using base::ASCIIToUTF16;
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
class BookmarkNameFolderControllerTest : public CocoaProfileTest {
};
// Simple add of a node (at the end).
TEST_F(BookmarkNameFolderControllerTest, AddNew) {
BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
const BookmarkNode* parent = model->bookmark_bar_node();
EXPECT_EQ(0, parent->child_count());
base::scoped_nsobject<BookmarkNameFolderController> controller(
[[BookmarkNameFolderController alloc] initWithParentWindow:test_window()
profile:profile()
parent:parent
newIndex:0]);
[controller window]; // force nib load
// Do nothing.
[controller cancel:nil];
EXPECT_EQ(0, parent->child_count());
// Change name then cancel.
[controller setFolderName:@"Bozo"];
[controller cancel:nil];
EXPECT_EQ(0, parent->child_count());
// Add a new folder.
[controller ok:nil];
EXPECT_EQ(1, parent->child_count());
EXPECT_TRUE(parent->GetChild(0)->is_folder());
EXPECT_EQ(ASCIIToUTF16("Bozo"), parent->GetChild(0)->GetTitle());
}
// Add new but specify a sibling.
TEST_F(BookmarkNameFolderControllerTest, AddNewWithSibling) {
BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
const BookmarkNode* parent = model->bookmark_bar_node();
// Add 2 nodes. We will place the new folder in the middle of these.
model->AddURL(parent, 0, ASCIIToUTF16("title 1"),
GURL("http://www.google.com"));
model->AddURL(parent, 1, ASCIIToUTF16("title 3"),
GURL("http://www.google.com"));
EXPECT_EQ(2, parent->child_count());
base::scoped_nsobject<BookmarkNameFolderController> controller(
[[BookmarkNameFolderController alloc] initWithParentWindow:test_window()
profile:profile()
parent:parent
newIndex:1]);
[controller window]; // force nib load
// Add a new folder.
[controller setFolderName:@"middle"];
[controller ok:nil];
// Confirm we now have 3, and that the new one is in the middle.
EXPECT_EQ(3, parent->child_count());
EXPECT_TRUE(parent->GetChild(1)->is_folder());
EXPECT_EQ(ASCIIToUTF16("middle"), parent->GetChild(1)->GetTitle());
}
// Make sure we are allowed to create a folder named "New Folder".
TEST_F(BookmarkNameFolderControllerTest, AddNewDefaultName) {
BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
const BookmarkNode* parent = model->bookmark_bar_node();
EXPECT_EQ(0, parent->child_count());
base::scoped_nsobject<BookmarkNameFolderController> controller(
[[BookmarkNameFolderController alloc] initWithParentWindow:test_window()
profile:profile()
parent:parent
newIndex:0]);
[controller window]; // force nib load
// Click OK without changing the name
[controller ok:nil];
EXPECT_EQ(1, parent->child_count());
EXPECT_TRUE(parent->GetChild(0)->is_folder());
}
// Make sure we are allowed to create a folder with an empty name.
TEST_F(BookmarkNameFolderControllerTest, AddNewBlankName) {
BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
const BookmarkNode* parent = model->bookmark_bar_node();
EXPECT_EQ(0, parent->child_count());
base::scoped_nsobject<BookmarkNameFolderController> controller(
[[BookmarkNameFolderController alloc] initWithParentWindow:test_window()
profile:profile()
parent:parent
newIndex:0]);
[controller window]; // force nib load
// Change the name to blank, click OK.
[controller setFolderName:@""];
[controller ok:nil];
EXPECT_EQ(1, parent->child_count());
EXPECT_TRUE(parent->GetChild(0)->is_folder());
}
TEST_F(BookmarkNameFolderControllerTest, Rename) {
BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
const BookmarkNode* parent = model->bookmark_bar_node();
const BookmarkNode* folder = model->AddFolder(parent,
parent->child_count(),
ASCIIToUTF16("folder"));
// Rename the folder by creating a controller that originates from
// the node.
base::scoped_nsobject<BookmarkNameFolderController> controller(
[[BookmarkNameFolderController alloc] initWithParentWindow:test_window()
profile:profile()
node:folder]);
[controller window]; // force nib load
EXPECT_NSEQ(@"folder", [controller folderName]);
[controller setFolderName:@"Zobo"];
[controller ok:nil];
EXPECT_EQ(1, parent->child_count());
EXPECT_TRUE(parent->GetChild(0)->is_folder());
EXPECT_EQ(ASCIIToUTF16("Zobo"), parent->GetChild(0)->GetTitle());
}
TEST_F(BookmarkNameFolderControllerTest, EditAndConfirmOKButton) {
BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
const BookmarkNode* parent = model->bookmark_bar_node();
EXPECT_EQ(0, parent->child_count());
base::scoped_nsobject<BookmarkNameFolderController> controller(
[[BookmarkNameFolderController alloc] initWithParentWindow:test_window()
profile:profile()
parent:parent
newIndex:0]);
[controller window]; // force nib load
// We start enabled since the default "New Folder" is added for us.
EXPECT_TRUE([[controller okButton] isEnabled]);
[controller setFolderName:@"Bozo"];
EXPECT_TRUE([[controller okButton] isEnabled]);
[controller setFolderName:@" "];
EXPECT_TRUE([[controller okButton] isEnabled]);
[controller setFolderName:@""];
EXPECT_TRUE([[controller okButton] isEnabled]);
}
......@@ -21,7 +21,6 @@
#include "chrome/browser/extensions/browser_extension_window_controller.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
......@@ -104,7 +103,6 @@ constexpr const gfx::Size kMinCocoaPopupWindowSize(100, 122);
StatusBubbleMac* statusBubble_;
std::unique_ptr<BookmarkBubbleObserverCocoa> bookmarkBubbleObserver_;
BookmarkBubbleController* bookmarkBubbleController_; // Weak.
BOOL initializing_; // YES while we are currently in initWithBrowser:
BOOL ownsBrowser_; // Only ever NO when testing
......
......@@ -42,7 +42,6 @@
#import "chrome/browser/ui/cocoa/background_gradient_view.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_observer_cocoa.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h"
#import "chrome/browser/ui/cocoa/browser/exclusive_access_controller_views.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
......@@ -443,7 +442,6 @@ bool IsTabDetachingInFullscreenEnabled() {
[downloadShelfController_ browserWillBeDestroyed];
[bookmarkBarController_ browserWillBeDestroyed];
[avatarButtonController_ browserWillBeDestroyed];
[bookmarkBubbleController_ browserWillBeDestroyed];
[super dealloc];
}
......@@ -1546,54 +1544,18 @@ bool IsTabDetachingInFullscreenEnabled() {
bookmarkBubbleObserver_.reset(new BookmarkBubbleObserverCocoa(self));
if (chrome::ShowPilotDialogsWithViewsToolkit()) {
chrome::ShowBookmarkBubbleViewsAtPoint(
gfx::ScreenPointFromNSPoint(ui::ConvertPointFromWindowToScreen(
[self window], [self bookmarkBubblePoint])),
[[self window] contentView], bookmarkBubbleObserver_.get(),
browser_.get(), url, alreadyMarked,
[self locationBarBridge]->star_decoration());
} else {
#if BUILDFLAG(MAC_VIEWS_BROWSER)
NOTREACHED() << "MacViews Browser can't show cocoa dialogs";
#else
BookmarkModel* model =
BookmarkModelFactory::GetForBrowserContext(browser_->profile());
bookmarks::ManagedBookmarkService* managed =
ManagedBookmarkServiceFactory::GetForProfile(browser_->profile());
const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url);
bookmarkBubbleController_ = [[BookmarkBubbleController alloc]
initWithParentWindow:[self window]
bubbleObserver:bookmarkBubbleObserver_.get()
managed:managed
model:model
node:node
alreadyBookmarked:alreadyMarked];
[bookmarkBubbleController_ showWindow:self];
#endif
}
DCHECK(bookmarkBubbleObserver_);
chrome::ShowBookmarkBubbleViewsAtPoint(
gfx::ScreenPointFromNSPoint(ui::ConvertPointFromWindowToScreen(
[self window], [self bookmarkBubblePoint])),
[[self window] contentView], bookmarkBubbleObserver_.get(),
browser_.get(), url, alreadyMarked,
[self locationBarBridge]->star_decoration());
}
- (void)bookmarkBubbleClosed {
// Nil out the weak bookmark bubble controller reference.
bookmarkBubbleController_ = nil;
bookmarkBubbleObserver_.reset();
}
// Handle the editBookmarkNode: action sent from bookmark bubble controllers.
- (void)editBookmarkNode:(id)sender {
BOOL responds = [sender respondsToSelector:@selector(node)];
DCHECK(responds);
if (responds) {
const BookmarkNode* node = [sender node];
if (node)
BookmarkEditor::Show([self window], browser_->profile(),
BookmarkEditor::EditDetails::EditNode(node),
BookmarkEditor::SHOW_TREE);
}
}
- (void)showTranslateBubbleForWebContents:(content::WebContents*)contents
step:(translate::TranslateStep)step
errorType:(translate::TranslateErrors::Type)
......
......@@ -335,11 +335,6 @@ willPositionSheet:(NSWindow*)sheet
NSWindow* sourceWindow = fullscreen ? regularWindow : fullscreenWindow;
NSWindow* destWindow = fullscreen ? fullscreenWindow : regularWindow;
// Close the bookmark bubble, if it's open. Use |-ok:| instead of |-cancel:|
// or |-close| because that matches the behavior when the bubble loses key
// status.
[bookmarkBubbleController_ ok:self];
// Save the current first responder so we can restore after views are moved.
base::scoped_nsobject<FocusTracker> focusTracker(
[[FocusTracker alloc] initWithWindow:sourceWindow]);
......
// Copyright 2017 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_COCOA_DIALOG_TEXT_FIELD__EDITOR_H_
#define CHROME_BROWSER_UI_COCOA_DIALOG_TEXT_FIELD__EDITOR_H_
#import <Cocoa/Cocoa.h>
// This class is used to customize the field editors for dialog textfields.
// It intercepts touch bar methods to prevent the textfield's touch bar from
// overriding the dialog's touch bar.
//
// TODO(spqchan): Add the textfield's candidate list to the touch bar. I've
// tried to combine the parent's touch bar with the dialog's, but the result
// was buggy.
@interface DialogTextFieldEditor : NSTextView
@end
#endif // CHROME_BROWSER_UI_COCOA_DIALOG_TEXT_FIELD__EDITOR_H_
\ No newline at end of file
// Copyright 2017 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.
#import "chrome/browser/ui/cocoa/dialog_text_field_editor.h"
#import "ui/base/cocoa/touch_bar_forward_declarations.h"
@implementation DialogTextFieldEditor
- (instancetype)init {
if ((self = [super init])) {
[self setFieldEditor:YES];
}
return self;
}
- (NSTouchBar*)makeTouchBar {
return nil;
}
@end
......@@ -4063,7 +4063,6 @@ test("unit_tests") {
"../browser/ui/cocoa/autofill/autofill_tooltip_controller_unittest.mm",
"../browser/ui/cocoa/background_gradient_view_unittest.mm",
"../browser/ui/cocoa/base_bubble_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_bar_bridge_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell_unittest.mm",
......@@ -4075,16 +4074,12 @@ test("unit_tests") {
"../browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h",
"../browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.mm",
"../browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_bubble_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_button_cell_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_button_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_editor_base_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_editor_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_folder_target_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_menu_bridge_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_model_observer_for_cocoa_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_name_folder_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_tree_browser_cell_unittest.mm",
"../browser/ui/cocoa/browser/zoom_bubble_controller_unittest.mm",
"../browser/ui/cocoa/browser_window_cocoa_unittest.mm",
......@@ -4219,10 +4214,6 @@ test("unit_tests") {
if (mac_views_browser) {
sources -= [
"../browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_bubble_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_editor_base_controller_unittest.mm",
"../browser/ui/cocoa/bookmarks/bookmark_editor_controller_unittest.mm",
"../browser/ui/cocoa/content_settings/collected_cookies_mac_unittest.mm",
"../browser/ui/cocoa/content_settings/cookie_details_unittest.mm",
"../browser/ui/cocoa/content_settings/cookie_details_view_controller_unittest.mm",
......
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