diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-08 22:14:38 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-08 22:14:38 +0000 |
commit | 91e81aeeccfb493d3503368d7b30a0f3b80a3478 (patch) | |
tree | 0d6b7049b614cb9e3aa9f29ff26a7ecaee0d9fc7 /views | |
parent | 5f9e0b82a61503101a80a3dee4df9f5b7017c8d1 (diff) | |
download | chromium_src-91e81aeeccfb493d3503368d7b30a0f3b80a3478.zip chromium_src-91e81aeeccfb493d3503368d7b30a0f3b80a3478.tar.gz chromium_src-91e81aeeccfb493d3503368d7b30a0f3b80a3478.tar.bz2 |
Move color_utils, text_elider, drag_utils, accessibility_types, standard_layout to new locations in app/ and views/
http://crbug.com/11387
Review URL: http://codereview.chromium.org/113143
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15687 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/DEPS | 61 | ||||
-rw-r--r-- | views/accessibility/accessibility_types.h | 48 | ||||
-rw-r--r-- | views/accessibility/view_accessibility.h | 8 | ||||
-rw-r--r-- | views/controls/label.cc | 2 | ||||
-rw-r--r-- | views/controls/menu/chrome_menu.cc | 5 | ||||
-rw-r--r-- | views/controls/message_box_view.cc | 4 | ||||
-rw-r--r-- | views/drag_utils.cc | 160 | ||||
-rw-r--r-- | views/drag_utils.h | 45 | ||||
-rw-r--r-- | views/standard_layout.h | 77 | ||||
-rw-r--r-- | views/view.h | 2 | ||||
-rw-r--r-- | views/views.vcproj | 16 | ||||
-rw-r--r-- | views/widget/tooltip_manager.cc | 2 | ||||
-rw-r--r-- | views/window/dialog_client_view.cc | 2 |
13 files changed, 382 insertions, 50 deletions
@@ -1,37 +1,24 @@ -include_rules = [
- "+app",
- "+skia/ext",
- "+skia/include",
-
- # TODO(beng): sever these dependencies into chrome by either refactoring or
- # moving code into app/
-
- # view.h
- "+chrome/common/accessibility_types.h",
-
- # view_unittest.cc
- "+chrome/browser/browser_process.h",
-
- # label.cc
- "+chrome/common/gfx/text_elider.h",
-
- # message_box_view.cc
- "+chrome/browser/views/standard_layout.h",
-
- # text_field.cc
- "+chrome/common/win_util.h",
-
- # widget_win.cc
- "+chrome/app/chrome_dll_resource.h",
-
- # window_delegate.cc
- "+chrome/common/pref_service.h",
-
- # chrome_menu.cc
- "+chrome/browser/drag_utils.h",
- "+chrome/common/gfx/color_utils.h",
-
- # TODO(beng): swap these with app/views specific generated resources.
- "+grit/generated_resources.h",
- "+grit/theme_resources.h",
-]
+include_rules = [ + "+app", + "+skia/ext", + "+skia/include", + + # TODO(beng): sever these dependencies into chrome by either refactoring or + # moving code into app/ + + # message_box_view.cc, text_field.cc, window_delegate.cc + "+chrome/browser/browser_process.h", + + # text_field.cc + "+chrome/common/win_util.h", + + # widget_win.cc + "+chrome/app/chrome_dll_resource.h", + + # window_delegate.cc + "+chrome/common/pref_service.h", + + # TODO(beng): swap these with app/views specific generated resources. + "+grit/generated_resources.h", + "+grit/theme_resources.h", +] diff --git a/views/accessibility/accessibility_types.h b/views/accessibility/accessibility_types.h new file mode 100644 index 0000000..32e4f73 --- /dev/null +++ b/views/accessibility/accessibility_types.h @@ -0,0 +1,48 @@ +// Copyright (c) 2006-2009 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 VIEWS_ACCESSIBILITY_ACCESSIBILITY_TYPES_H_ +#define VIEWS_ACCESSIBILITY_ACCESSIBILITY_TYPES_H_ + +//////////////////////////////////////////////////////////////////////////////// +// +// AccessibilityTypes +// +// Provides enumerations used to preserve platform-independence in accessibility +// functions used in various Views, both in Browser\Views and Views. +// +//////////////////////////////////////////////////////////////////////////////// +class AccessibilityTypes { + public: + // This defines an enumeration of the supported accessibility roles in our + // Views (e.g. used in View::GetAccessibleRole). Any interface using roles + // must provide a conversion to its own roles (see e.g. + // ViewAccessibility::get_accRole and ViewAccessibility::MSAARole). + enum Role { + ROLE_APPLICATION, + ROLE_BUTTONDROPDOWN, + ROLE_CLIENT, + ROLE_GROUPING, + ROLE_PAGETAB, + ROLE_PUSHBUTTON, + ROLE_TEXT, + ROLE_TOOLBAR + }; + + // This defines an enumeration of the supported accessibility roles in our + // Views (e.g. used in View::GetAccessibleState). Any interface using roles + // must provide a conversion to its own roles (see e.g. + // ViewAccessibility::get_accState and ViewAccessibility::MSAAState). + enum State { + STATE_HASPOPUP, + STATE_READONLY + }; + + private: + // Do not instantiate this class. + AccessibilityTypes() {} + ~AccessibilityTypes() {} +}; + +#endif // VIEWS_ACCESSIBILITY_ACCESSIBILITY_TYPES_H_ diff --git a/views/accessibility/view_accessibility.h b/views/accessibility/view_accessibility.h index 840a685..bc1c26f 100644 --- a/views/accessibility/view_accessibility.h +++ b/views/accessibility/view_accessibility.h @@ -127,12 +127,12 @@ class ATL_NO_VTABLE ViewAccessibility // Helper function which sets applicable states of view. void SetState(VARIANT* msaa_state, views::View* view); - // Returns a conversion from the Role (as defined in - // chrome/common/accessibility_types.h) to an MSAA role. + // Returns a conversion from the Role (as defined in accessibility_types.h) + // to an MSAA role. long MSAARole(AccessibilityTypes::Role role); - // Returns a conversion from the State (as defined in - // chrome/common/accessibility_types.h) to MSAA states set. + // Returns a conversion from the State (as defined in accessibility_types.h) + // to MSAA states set. long MSAAState(AccessibilityTypes::State state); // Member View needed for view-specific calls. diff --git a/views/controls/label.cc b/views/controls/label.cc index 1dc0b54..ceb9fa1 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -9,11 +9,11 @@ #include "app/gfx/chrome_canvas.h" #include "app/gfx/chrome_font.h" #include "app/gfx/insets.h" +#include "app/gfx/text_elider.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/logging.h" #include "base/string_util.h" -#include "chrome/common/gfx/text_elider.h" #include "views/background.h" namespace views { diff --git a/views/controls/menu/chrome_menu.cc b/views/controls/menu/chrome_menu.cc index a887fd5..203fb88 100644 --- a/views/controls/menu/chrome_menu.cc +++ b/views/controls/menu/chrome_menu.cc @@ -9,6 +9,7 @@ #include <Vssym32.h> #include "app/gfx/chrome_canvas.h" +#include "app/gfx/color_utils.h" #include "app/l10n_util.h" #include "app/l10n_util_win.h" #include "app/os_exchange_data.h" @@ -18,12 +19,10 @@ #include "base/task.h" #include "base/timer.h" #include "base/win_util.h" -// TODO(beng): (Cleanup) remove this browser dep. -#include "chrome/browser/drag_utils.h" -#include "chrome/common/gfx/color_utils.h" #include "grit/generated_resources.h" #include "skia/ext/skia_utils_win.h" #include "views/border.h" +#include "views/drag_utils.h" #include "views/view_constants.h" #include "views/widget/root_view.h" #include "views/widget/widget_win.h" diff --git a/views/controls/message_box_view.cc b/views/controls/message_box_view.cc index d9c45c2..456bb6e 100644 --- a/views/controls/message_box_view.cc +++ b/views/controls/message_box_view.cc @@ -11,10 +11,10 @@ #include "base/scoped_clipboard_writer.h" #include "base/string_util.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/views/standard_layout.h" +#include "grit/generated_resources.h" #include "views/controls/button/checkbox.h" +#include "views/standard_layout.h" #include "views/window/client_view.h" -#include "grit/generated_resources.h" static const int kDefaultMessageWidth = 320; diff --git a/views/drag_utils.cc b/views/drag_utils.cc new file mode 100644 index 0000000..271e683 --- /dev/null +++ b/views/drag_utils.cc @@ -0,0 +1,160 @@ +// Copyright (c) 2006-2008 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 "views/drag_utils.h" + +#include <objidl.h> +#include <shlobj.h> +#include <shobjidl.h> + +#include "app/gfx/chrome_canvas.h" +#include "app/gfx/chrome_font.h" +#include "app/l10n_util.h" +#include "app/os_exchange_data.h" +#include "app/resource_bundle.h" +#include "base/file_util.h" +#include "base/gfx/gdi_util.h" +#include "base/gfx/point.h" +#include "base/string_util.h" +#include "chrome/common/win_util.h" +#include "googleurl/src/gurl.h" +#include "grit/theme_resources.h" +#include "views/controls/button/text_button.h" + +namespace drag_utils { + +// Maximum width of the link drag image in pixels. +static const int kLinkDragImageMaxWidth = 200; +static const int kLinkDragImageVPadding = 3; +static const int kLinkDragImageVSpacing = 2; +static const int kLinkDragImageHPadding = 4; +static const SkColor kLinkDragImageBGColor = SkColorSetRGB(131, 146, 171); +//static const SkColor kLinkDragImageBGColor = SkColorSetRGB(195, 217, 255); +static const SkColor kLinkDragImageTextColor = SK_ColorBLACK; + +// File dragging pixel measurements +static const int kFileDragImageMaxWidth = 200; +static const SkColor kFileDragImageTextColor = SK_ColorBLACK; + +static void SetDragImageOnDataObject(HBITMAP hbitmap, + int width, + int height, + int cursor_offset_x, + int cursor_offset_y, + IDataObject* data_object) { + IDragSourceHelper* helper = NULL; + HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, + IID_IDragSourceHelper, reinterpret_cast<LPVOID*>(&helper)); + if (SUCCEEDED(rv)) { + SHDRAGIMAGE sdi; + sdi.sizeDragImage.cx = width; + sdi.sizeDragImage.cy = height; + sdi.crColorKey = 0xFFFFFFFF; + sdi.hbmpDragImage = hbitmap; + sdi.ptOffset.x = cursor_offset_x; + sdi.ptOffset.y = cursor_offset_y; + helper->InitializeFromBitmap(&sdi, data_object); + } +}; + +// Blit the contents of the canvas to a new HBITMAP. It is the caller's +// responsibility to release the |bits| buffer. +static HBITMAP CreateBitmapFromCanvas(const ChromeCanvas& canvas, + int width, + int height) { + HDC screen_dc = GetDC(NULL); + BITMAPINFOHEADER header; + gfx::CreateBitmapHeader(width, height, &header); + void* bits; + HBITMAP bitmap = + CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header), + DIB_RGB_COLORS, &bits, NULL, 0); + HDC compatible_dc = CreateCompatibleDC(screen_dc); + HGDIOBJ old_object = SelectObject(compatible_dc, bitmap); + BitBlt(compatible_dc, 0, 0, width, height, + canvas.getTopPlatformDevice().getBitmapDC(), + 0, 0, SRCCOPY); + SelectObject(compatible_dc, old_object); + ReleaseDC(NULL, compatible_dc); + ReleaseDC(NULL, screen_dc); + return bitmap; +} + +void SetURLAndDragImage(const GURL& url, + const std::wstring& title, + const SkBitmap& icon, + OSExchangeData* data) { + DCHECK(url.is_valid() && data); + + data->SetURL(url, title); + + // Create a button to render the drag image for us. + views::TextButton button(NULL, + title.empty() ? UTF8ToWide(url.spec()) : title); + button.set_max_width(kLinkDragImageMaxWidth); + if (icon.isNull()) { + button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_DEFAULT_FAVICON)); + } else { + button.SetIcon(icon); + } + gfx::Size prefsize = button.GetPreferredSize(); + button.SetBounds(0, 0, prefsize.width(), prefsize.height()); + + // Render the image. + ChromeCanvas canvas(prefsize.width(), prefsize.height(), false); + button.Paint(&canvas, true); + SetDragImageOnDataObject(canvas, prefsize.width(), prefsize.height(), + prefsize.width() / 2, prefsize.height() / 2, + data); +} + +void CreateDragImageForFile(const std::wstring& file_name, + SkBitmap* icon, + IDataObject* data_object) { + DCHECK(icon); + DCHECK(data_object); + + // Set up our text portion + const std::wstring& name = file_util::GetFilenameFromPath(file_name); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + ChromeFont font = rb.GetFont(ResourceBundle::BaseFont); + + const int width = kFileDragImageMaxWidth; + // Add +2 here to allow room for the halo. + const int height = font.height() + icon->height() + + kLinkDragImageVPadding + 2; + ChromeCanvas canvas(width, height, false /* translucent */); + + // Paint the icon. + canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); + + // Paint the file name. We inset it one pixel to allow room for the halo. + canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, + 1, icon->height() + kLinkDragImageVPadding + 1, + width - 2, font.height(), + ChromeCanvas::TEXT_ALIGN_CENTER); + + SetDragImageOnDataObject(canvas, width, height, width / 2, + kLinkDragImageVPadding, data_object); +} + +void SetDragImageOnDataObject(const ChromeCanvas& canvas, + int width, + int height, + int cursor_x_offset, + int cursor_y_offset, + IDataObject* data_object) { + DCHECK(data_object && width > 0 && height > 0); + // SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap. + HBITMAP bitmap = CreateBitmapFromCanvas(canvas, width, height); + + // Attach 'bitmap' to the data_object. + SetDragImageOnDataObject(bitmap, width, height, + cursor_x_offset, + cursor_y_offset, + data_object); +} + +} // namespace drag_utils diff --git a/views/drag_utils.h b/views/drag_utils.h new file mode 100644 index 0000000..22855cfa --- /dev/null +++ b/views/drag_utils.h @@ -0,0 +1,45 @@ +// Copyright (c) 2006-2008 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 VIEWS_DRAG_UTILS_H_ +#define VIEWS_DRAG_UTILS_H_ + +#include <objidl.h> +#include <string> + +class ChromeCanvas; +class GURL; +class OSExchangeData; +class SkBitmap; + +namespace drag_utils { + +// Sets url and title on data as well as setting a suitable image for dragging. +// The image looks like that of the bookmark buttons. +void SetURLAndDragImage(const GURL& url, + const std::wstring& title, + const SkBitmap& icon, + OSExchangeData* data); + +// Creates a dragging image to be displayed when the user drags a file from +// Chrome (via the download manager, for example). The drag image is set into +// the supplied data_object. 'file_name' can be a full path, but the directory +// portion will be truncated in the drag image. +void CreateDragImageForFile(const std::wstring& file_name, + SkBitmap* icon, + IDataObject* data_object); + +// Sets the drag image on data_object from the supplied canvas. width/height +// are the size of the image to use, and the offsets give the location of +// the hotspot for the drag image. +void SetDragImageOnDataObject(const ChromeCanvas& canvas, + int width, + int height, + int cursor_x_offset, + int cursor_y_offset, + IDataObject* data_object); + +} // namespace drag_utils + +#endif // #ifndef VIEWS_DRAG_UTILS_H_ diff --git a/views/standard_layout.h b/views/standard_layout.h new file mode 100644 index 0000000..a96fe44 --- /dev/null +++ b/views/standard_layout.h @@ -0,0 +1,77 @@ +// Copyright (c) 2006-2008 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 VIEWS_STANDARD_LAYOUT_H_ +#define VIEWS_STANDARD_LAYOUT_H_ + +#include "views/grid_layout.h" + +// +// This file contains some constants we use to implement our standard panel +// layout. +// see: spec 21/4 + +// Left or right margin. +const int kPanelHorizMargin = 13; + +// Top or bottom margin. +const int kPanelVertMargin = 13; + +// If some UI has some sub UI. Indent horizontally by the following value. +const int kPanelHorizIndentation = 24; + +// When several controls are aligned vertically, the baseline should be spaced +// by the following number of pixels. +const int kPanelVerticalSpacing = 32; + +// Vertical spacing between sub UI. +const int kPanelSubVerticalSpacing = 24; + +// Vertical spacing between a label and some control. +const int kLabelToControlVerticalSpacing = 8; + +// Vertical spacing between controls that are logically related. +const int kRelatedControlVerticalSpacing = 8; + +// Small vertical spacing between controls that are logically related. +const int kRelatedControlSmallVerticalSpacing = 4; + +// Vertical spacing between controls that are logically unrelated. +const int kUnrelatedControlVerticalSpacing = 20; + +// Larger vertical spacing between unrelated controls. +const int kUnrelatedControlLargeVerticalSpacing = 30; + +// Small horizontal spacing between controls that are logically related. +const int kRelatedControlSmallHorizontalSpacing = 8; + +// Horizontal spacing between controls that are logically related. +const int kRelatedControlHorizontalSpacing = 8; + +// Horizontal spacing between controls that are logically unrelated. +const int kUnrelatedControlHorizontalSpacing = 12; + +// Larger horizontal spacing between unrelated controls. +const int kUnrelatedControlLargeHorizontalSpacing = 20; + +// Vertical spacing between the edge of the window and the +// top or bottom of a button. +const int kButtonVEdgeMargin = 6; + +// Vertical spacing between the edge of the window and the +// left or right of a button. +const int kButtonHEdgeMargin = 7; + +// Horizontal spacing between buttons that are logically related. +const int kRelatedButtonHSpacing = 6; + +// Creates a GridLayout with kPanel*Margin insets. +static views::GridLayout* CreatePanelGridLayout(views::View* host) { + views::GridLayout* layout = new views::GridLayout(host); + layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, + kPanelVertMargin, kPanelHorizMargin); + return layout; +} + +#endif // VIEWS_STANDARD_LAYOUT_H_ diff --git a/views/view.h b/views/view.h index e004e03..e3a78f7 100644 --- a/views/view.h +++ b/views/view.h @@ -20,8 +20,8 @@ #include "base/gfx/rect.h" #include "base/scoped_ptr.h" -#include "chrome/common/accessibility_types.h" #include "views/accelerator.h" +#include "views/accessibility/accessibility_types.h" #include "views/background.h" #include "views/border.h" diff --git a/views/views.vcproj b/views/views.vcproj index c10e68d..2c98260 100644 --- a/views/views.vcproj +++ b/views/views.vcproj @@ -125,6 +125,10 @@ Name="accessibility" > <File + RelativePath=".\accessibility\accessibility_types.h" + > + </File> + <File RelativePath=".\accessibility\view_accessibility.cc" > </File> @@ -776,6 +780,14 @@ > </File> <File + RelativePath=".\drag_utils.cc" + > + </File> + <File + RelativePath=".\drag_utils.h" + > + </File> + <File RelativePath=".\event.cc" > </File> @@ -844,6 +856,10 @@ > </File> <File + RelativePath=".\standard_layout.h" + > + </File> + <File RelativePath=".\view.cc" > </File> diff --git a/views/widget/tooltip_manager.cc b/views/widget/tooltip_manager.cc index 18faf4a..114a032 100644 --- a/views/widget/tooltip_manager.cc +++ b/views/widget/tooltip_manager.cc @@ -6,11 +6,11 @@ #include <limits> +#include "app/gfx/text_elider.h" #include "app/l10n_util.h" #include "app/l10n_util_win.h" #include "base/logging.h" #include "base/message_loop.h" -#include "chrome/common/gfx/text_elider.h" #include "chrome/common/win_util.h" #include "views/view.h" #include "views/widget/root_view.h" diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc index b7989ac..17fc332 100644 --- a/views/window/dialog_client_view.cc +++ b/views/window/dialog_client_view.cc @@ -13,9 +13,9 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/gfx/native_theme.h" -#include "chrome/browser/views/standard_layout.h" #include "grit/generated_resources.h" #include "views/controls/button/native_button.h" +#include "views/standard_layout.h" #include "views/window/dialog_delegate.h" #include "views/window/window.h" |