File: bookmark_folder_target.mm

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (108 lines) | stat: -rw-r--r-- 4,366 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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_folder_target.h"

#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/profiles/profile_manager.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node_data.h"
#include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h"
#include "ui/base/clipboard/clipboard_util_mac.h"
#import "ui/base/cocoa/cocoa_base_utils.h"

using bookmarks::BookmarkNode;
using bookmarks::BookmarkNodeData;

NSString* kBookmarkButtonDragType = @"com.google.chrome.BookmarkButtonDrag";

@implementation BookmarkFolderTarget

- (id)initWithController:(id<BookmarkButtonControllerProtocol>)controller
                 profile:(Profile*)profile {
  if ((self = [super init])) {
    controller_ = controller;
    profile_ = profile;
  }
  return self;
}

// This IBAction is called when the user clicks (mouseUp, really) on a
// "folder" bookmark button.  (In this context, "Click" does not
// include right-click to open a context menu which follows a
// different path).  Scenarios when folder X is clicked:
//  *Predicate*        *Action*
//  (nothing)          Open Folder X
//  Folder X open      Close folder X
//  Folder Y open      Close Y, open X
//  Cmd-click          Open All with proper disposition
//
//  Note complication in which a click-drag engages drag and drop, not
//  a click-to-open.  Thus the path to get here is a little twisted.
- (IBAction)openBookmarkFolderFromButton:(id)sender {
  DCHECK(sender);
  // Watch out for a modifier click.  For example, command-click
  // should open all.
  //
  // NOTE: we cannot use [[sender cell] mouseDownFlags] because we
  // thwart the normal mouse click mechanism to make buttons
  // draggable.  Thus we must use [NSApp currentEvent].
  //
  // Holding command while using the scroll wheel (or moving around
  // over a bookmark folder) can confuse us.  Unless we check the
  // event type, we are not sure if this is an "open folder" due to a
  // hover-open or "open folder" due to a click.  It doesn't matter
  // (both do the same thing) unless a modifier is held, since
  // command-click should "open all" but command-move should not.
  // WindowOpenDispositionFromNSEvent does not consider the event
  // type; only the modifiers.  Thus the need for an extra
  // event-type-check here.
  DCHECK([sender bookmarkNode]->is_folder());
  NSEvent* event = [NSApp currentEvent];
  WindowOpenDisposition disposition =
      ui::WindowOpenDispositionFromNSEvent(event);
  if (([event type] != NSMouseEntered) && ([event type] != NSMouseMoved) &&
      ([event type] != NSScrollWheel) &&
      (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)) {
    [controller_ closeAllBookmarkFolders];
    [controller_ openAll:[sender bookmarkNode] disposition:disposition];
    return;
  }

  // If click on same folder, close it and be done.
  // Else we clicked on a different folder so more work to do.
  if ([[controller_ folderController] parentButton] == sender) {
    [controller_ closeBookmarkFolder:controller_];
    return;
  }

  [controller_ addNewFolderControllerWithParentButton:sender];
}

- (NSPasteboardItem*)pasteboardItemForDragOfButton:(BookmarkButton*)button {
  const BookmarkNode* node = [button bookmarkNode];
  DCHECK(node);

  NSPasteboardItem* item = nil;
  if (node->is_folder()) {
    // TODO(viettrungluu): I'm not sure what we should do, so just declare the
    // "additional" types we're given for now. Maybe we want to add a list of
    // URLs? Would we then have to recurse if there were subfolders?
    item = [[[NSPasteboardItem alloc] init] autorelease];
  } else {
    BookmarkNodeData data(node);
    data.SetOriginatingProfilePath(profile_->GetPath());
    item = PasteboardItemFromBookmarks(data.elements, profile_->GetPath());
  }

  [item
      setData:[NSData dataWithBytes:&button length:sizeof(button)]
      forType:ui::ClipboardUtil::UTIForPasteboardType(kBookmarkButtonDragType)];
  return item;
}

@end