1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "ash/shelf/shelf_util.h" 6 7#include "ash/shelf/shelf_constants.h" 8#include "ui/aura/window_property.h" 9 10DECLARE_WINDOW_PROPERTY_TYPE(ash::ShelfID); 11DECLARE_WINDOW_PROPERTY_TYPE(ash::ShelfItemDetails*); 12 13namespace ash { 14 15DEFINE_WINDOW_PROPERTY_KEY(ShelfID, kShelfID, kInvalidShelfID); 16 17// ShelfItemDetails for kShelfItemDetaildKey is owned by the window 18// and will be freed automatically. 19DEFINE_OWNED_WINDOW_PROPERTY_KEY(ShelfItemDetails, 20 kShelfItemDetailsKey, 21 NULL); 22 23void SetShelfIDForWindow(ShelfID id, aura::Window* window) { 24 if (!window) 25 return; 26 27 window->SetProperty(kShelfID, id); 28} 29 30ShelfID GetShelfIDForWindow(const aura::Window* window) { 31 DCHECK(window); 32 return window->GetProperty(kShelfID); 33} 34 35void SetShelfItemDetailsForWindow(aura::Window* window, 36 const ShelfItemDetails& details) { 37 // |item_details| is owned by |window|. 38 ShelfItemDetails* item_details = new ShelfItemDetails(details); 39 window->SetProperty(kShelfItemDetailsKey, item_details); 40} 41 42void SetShelfItemDetailsForDialogWindow(aura::Window* window, 43 int image_resource_id) { 44 // |item_details| is owned by |window|. 45 ShelfItemDetails* item_details = new ShelfItemDetails; 46 item_details->type = TYPE_DIALOG; 47 item_details->image_resource_id = image_resource_id; 48 item_details->title = window->title(); 49 window->SetProperty(kShelfItemDetailsKey, item_details); 50} 51 52void ClearShelfItemDetailsForWindow(aura::Window* window) { 53 window->ClearProperty(kShelfItemDetailsKey); 54} 55 56const ShelfItemDetails* GetShelfItemDetailsForWindow( 57 aura::Window* window) { 58 return window->GetProperty(kShelfItemDetailsKey); 59} 60 61} // namespace ash 62